How to restart an Android app?

Thanks for the response. I am using below code to set capabilities through script.

def Initialize():
global driver
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘platformVersion’] = ‘6.0.1’
desired_caps[‘deviceName’] = ‘03157df33b83e813’
desired_caps[‘appPackage’] = ‘package name’
desired_caps[‘appActivity’] = ’ activity name’
driver = webdriver.Remote(‘http://localhost:4726/wd/hub’, desired_caps)
return driver

post initialisation, i do some actions on this application. Now, i want to restart the application continue with some more actions on this application. So, how do i handle the restart of application through code ? Do i need to quit driver & then reinitialise again ( using : driver = webdriver.Remote(‘http://localhost:4726/wd/hub’, desired_caps) ?

Hope my explanation is clear!

We’re still using Appium version 1.4.13. If you are using a newer version YMMV.

We use the following code to start the app when needed

  app_hash = {
      app_package: 'package_name',
      app_activity: 'activity_name'
  }
  appium_driver.start_activity app_hash

We use adb to stop our app – while I know that this is discouraged by the appium designers, there wasn’t a reliable method to stop the app otherwise.

Apologies for the delayed response.

As mentioned in my previous response, we are initialising the driver then quit the driver once certain actions are performed. then again reinitialise the driver to perform next set of actions.
Not sure if this is the ideal way of doing it. Since we are not able to use launchapp/closeapp method using python, we have used quit & reinitialise driver itself.

Thanks for the support willosser.

Is there any solution for this with the Appium Java client? I’m using version 6.1.0.

Edit: Found the solution. driver.resetApp(); Does the trick.

2nd Edit: But this method seems to open random apps on the phone in between my tests :face_with_raised_eyebrow:

Edit: Found the solution. driver.resetApp(); Does the trick.

@mni But it resets the state of the application right. In order to hold the data and restart the application how would you achieve it?