Not able to swicth back from 2nd app to 1st app?

Hi All,

Need help on below issue.

I could able launch the settings app in android device using DesiredCapabilities and did some actions in that app and switched to gmail app using Activity class with the package and activityname of gamil and did some actions in that app and then while switching back to the settings app by using Activity class with the package and activityname of the settings app then getting below error.

ERROR - org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot start the ‘com.android.settings’ application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: ‘Command ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am start -W -n com.android.settings/com.android.settings.Settings’ timed out after 20000ms’. Try to increase the 20000ms adb execution timeout represented by ‘adbExecTimeout’ capability
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘xxx’, ip: ‘172.16.13.166’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_191’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: com.android.settings.Settings, appPackage: com.android.settings, appiumVersion: 1.14.0, automationName: UiAutomator2, databaseEnabled: false, desired: {appActivity: com.android.settings.Settings, appPackage: com.android.settings, appiumVersion: 1.14.0, automationName: UiAutomator2, deviceName: Androdi SDK build for x86, noReset: true, platformName: android, platformVersion: 9, udid: emulator-5554}, deviceApiLevel: 28, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenDensity: 400, deviceScreenSize: 1080x2160, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.5, platform: LINUX, platformName: Android, platformVersion: 9, statBarHeight: 60, takesScreenshot: true, udid: emulator-5554, viewportRect: {height: 1980, left: 0, top: 60, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 2a0929fb-d2ce-42ee-828e-fdb726ede772

APPIUM logs:

[HTTP] --> POST /wd/hub/session/2a0929fb-d2ce-42ee-828e-fdb726ede772/appium/device/start_activity

[HTTP] {“appPackage”:“com.android.settings”,“appActivity”:“com.android.settings.Settings”,“appWaitPackage”:“com.android.settings”,“appWaitActivity”:“com.android.settings.Settings”,“dontStopAppOnReset”:true,“intentAction”:"",“intentCategory”:"",“intentFlags”:"",“optionalIntentArguments”:""}

[W3C (2a0929fb)] Calling AppiumDriver.startActivity() with args: [“com.android.settings”,“com.android.settings.Settings”,“com.android.settings”,“com.android.settings.Settings”,"","","","",true,null,null,“2a0929fb-d2ce-42ee-828e-fdb726ede772”]

[AndroidDriver] Starting package ‘com.android.settings’ and activity ‘com.android.settings.Settings’

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am start -W -n com.android.settings/com.android.settings.Settings’

[W3C (2a0929fb)] Encountered internal error running command: Error: Cannot start the ‘com.android.settings’ application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: ‘Command ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am start -W -n com.android.settings/com.android.settings.Settings’ timed out after 20000ms’. Try to increase the 20000ms adb execution timeout represented by ‘adbExecTimeout’ capability

[W3C (2a0929fb)] at ADB. (C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-utils.js:149:11)

[W3C (2a0929fb)] at Generator.throw ()

[W3C (2a0929fb)] at asyncGeneratorStep (C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\[email protected]\runtime\helpers\asyncToGenerator.js:3:24)

[W3C (2a0929fb)] at _throw (C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\[email protected]\runtime\helpers\asyncToGenerator.js:29:9)

[W3C (2a0929fb)] at run (C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules\es6.promise.js:75:22)

[W3C (2a0929fb)] at C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules\es6.promise.js:92:30

[W3C (2a0929fb)] at flush (C:\Users\xxx\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\core-js\modules_microtask.js:18:9)

[W3C (2a0929fb)] at process._tickCallback (internal/process/next_tick.js:61:11)

[HTTP] <-- POST /wd/hub/session/2a0929fb-d2ce-42ee-828e-fdb726ede772/appium/device/start_activity 500 20159 ms - 1753

[HTTP]

[HTTP] --> DELETE /wd/hub/session/2a0929fb-d2ce-42ee-828e-fdb726ede772

[HTTP] {}

[W3C (2a0929fb)] Calling AppiumDriver.deleteSession() with args: [“2a0929fb-d2ce-42ee-828e-fdb726ede772”]

[BaseDriver] Event ‘quitSessionRequested’ logged at 1566973719646 (11:58:39 GMT+0530 (India Standard Time))

[Appium] Removing session 2a0929fb-d2ce-42ee-828e-fdb726ede772 from our master session list

[UiAutomator2] Deleting UiAutomator2 session

[UiAutomator2] Deleting UiAutomator2 server session

[WD Proxy] Matched ‘/’ to command name ‘deleteSession’

[WD Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/d1e398aa-e70e-40c2-8804-5b201a2927f1] with no body

[WD Proxy] Got response with status 200: “{“sessionId”:“d1e398aa-e70e-40c2-8804-5b201a2927f1”,“status”:0,“value”:“Session deleted”}”

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop com.android.settings’

[Instrumentation] .

[Logcat] Stopping logcat capture

[ADB] Removing forwarded port socket connection: 8200

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp:8200’

[UiAutomator2] Restoring hidden api policy to the device default configuration

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy_pre_p_apps’

[Instrumentation] Time: 155.135

[Instrumentation]

[Instrumentation] OK (1 test)

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy_p_apps’

[Instrumentation] The process has exited with code 0

[ADB] Running ‘C:\Users\xxx\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy’

[BaseDriver] Event ‘quitSessionFinished’ logged at 1566973723076 (11:58:43 GMT+0530 (India Standard Time))

[W3C (2a0929fb)] Received response: null

[W3C (2a0929fb)] But deleting session, so not returning

[W3C (2a0929fb)] Responding to client with driver.deleteSession() result: null

[HTTP] <-- DELETE /wd/hub/session/2a0929fb-d2ce-42ee-828e-fdb726ede772 200 3432 ms - 14

[HTTP]

Appium server stopped successfully

{“appPackage”:“com.android.settings”,“appActivity”:“com.android.settings.Settings”,“appWaitPackage”:“com.android.settings”,“appWaitActivity”:“com.android.settings.Settings”,“dontStopAppOnReset”:true,“intentAction”:"",“intentCategory”:"",“intentFlags”:"",“optionalIntentArguments”:""}

-> com.android.settings - hardly believe this is your initial app.
pls add code so we can understand…

Hi Aleksei,

Setting app is initial. after that moved to gmail app successfully then I tried to move to setting app using startActive method. But couldn’t and getting the error. If i do key back then working without any issue.

@syamp try:

driver.runAppInBackground(1sec)

It should restore your previous app you started with.

If it gives exception use try-catch

Thanks for the reply @Aleksei. There is no method runAppInBackground() in java_client 7.0.0 and appium 1.14.0.

It is. You may look at example: https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Might be am i doing wrong. I couldn’t able see the method. please see the attached screenshot.

@syamp try add: ((AndroidDriver) driver).runApp…

Or AppiumDriver…