start · quit · sessions · close
This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET
Start or end the session on a device. These call app_session.
start
public Mobium start()
Connects and opens the session on the device: the device-side server is started now and, given an
app, it is launched and in front when this returns.
Nothing requires it -- every call opens a session on first use --
but it puts the slow first start (installing UiAutomator2, building
WebDriverAgent on an iPhone) where it was asked for. End it with
Mobium#quit(), or in try-with-resources, which quits:
try (Mobium device = Mobium.builder().platform("android").app("com.android.settings").start()) {
device.map();
}
}```
@return a device with its session open
## `quit`
```java
public void quit()
Ends the session on the device and closes the connection. The teardown is the daemon's own: accessibility settings put
back, a recording or route stopped, WebViews detached, the device-side
server stopped, and the app start() launched, if any, stopped
too. Quitting a session that is not open succeeds, and a second quit --
say, try-with-resources closing after an explicit one -- does nothing.
A program that exits without quitting or closing has the sessions it
started ended for it: mobium sees the client go.
sessions
public List<Map<String, Object>> sessions()
The sessions open on the daemon.
@return each with device, platform and driver
close
public void close()
Quits an instance from Builder#start(), whose session was opened
for this block; closes one from connect(), leaving the session
to whoever opened it.
Examples
Start a session and launch the app fresh
Mobium phone = Mobium.builder().app("com.android.settings").start();
System.out.println(phone.session().device());
The same call from the command line, mobium session start --app com.android.settings, printed on an Android 15 emulator:
session already open on emulator-5554 (android, uiautomator2); com.android.settings was launched fresh and is in the foreground
End it, putting back what it changed
device.quit(); // also closes the connection
The same call from the command line, mobium session end, printed on an Android 15 emulator:
session ended on emulator-5554; anything it changed for the session is put back; com.android.settings, which the session launched, was stopped
More examples
Open a session and launch the app fresh
try (Mobium phone = Mobium.builder().platform("ios").app("com.example.shop").start()) {
Session s = phone.session();
System.out.println(s.device() + " " + s.driver());
} // try-with-resources quits: the session ends here
End the session explicitly
Mobium phone = Mobium.builder().app("com.example.shop").start();
try {
phone.tap("text=Sign in");
} finally {
phone.quit(); // puts back what the session changed
}
Close a connection, leaving the session open
Mobium phone = Mobium.connect();
phone.tap("@e2");
phone.close(); // safe to call twice
List the sessions open on the daemon
for (Map<String, Object> s : device.sessions()) {
System.out.println(s.get("device") + " " + s.get("platform"));
}