Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically sending an app to background

Is there a way to send the application to background? Similarly to how you can call XCUIApplication.terminate(), I have some UI Elements to test on applicationDidBecomeActive(_:). Does anyone know if this is at all possible?

like image 776
Liam Avatar asked Nov 11 '15 14:11

Liam


People also ask

What does it mean when an app is backgrounded?

Background refers to the data used when the app is doing some activity in the background, which is not active right now. This is due to the fact that whether they are active or not, apps consume data. They may be. checking for updates or refreshing the user content.

How can I make a service run continuously on Android?

1: You have to invoke the service's startForeground() method within 5 seconds after starting the service. To do this, you can call startForeground() in onCreate() method of service. public class AppService extends Service { .... @Override public void onCreate() { startForeground(9999, Notification()) } .... }

How do I close background apps in Android programmatically?

You can use Process. killProcess(int pid) to kill processes that have the same UID with your App. You can use ActivityManager. killBackgroundProcesses(String packageName),with KILL_BACKGROUND_PROCESSES permission in your manifest(for API >= 8) or ActivityManager.


1 Answers

I would recommend checking out XCUIDevice. Here is how you might press the home button and then relaunch the application

func testExample() {

    // Has a nav bar.
    XCTAssert(XCUIApplication().navigationBars.element.exists)

    XCUIDevice().press(XCUIDeviceButton.home)
    // Before Swift 3: XCUIDevice().pressButton(XCUIDeviceButton.Home)
    XCUIApplication().launch()

    // Navigationbar still there on second launch.
    XCTAssert(XCUIApplication().navigationBars.element.exists)
}
like image 118
JMFR Avatar answered Sep 20 '22 12:09

JMFR