How to open a background app in Android Device

  1. ((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.HOME) - click home button to close app
    [15:57:17]

  2. sleep(10000); //sleep for 10 seconds

  3. driver.runAppInBackground(1)// open an background

When i use this driver.runAppInBackground(1) command, background app is opening and working perfectly and am getting following error

An unknown server-side error occurred while processing the command. (Original error: com.sec.android.app.launcher/com.android.launcher2.Launcher never started. Current: com.qa/.v2.NavigationActivity) (WARNING: The server did not provide any stacktrace information)(…)

Is there any alternative command available?

              // Press Home Key
	_driver.sendKeyEvent(AndroidKeyCode.HOME);
	
	// KEYCODE_APP_SWITCH
	_driver.sendKeyEvent(187);
            
            // maximize app
	_driver.findElementByAccessibilityId("app1Name");

@amitjaincoer191 I got it working by following code

  1. ((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.HOME);

  2. ((AndroidDriver) driver).sendKeyEvent(187);

  3. driver.findElementById(“com.android.systemui:id/activity_description”).click();

try with appium java client 3.2.0
((AndroidDriver)appiumDriver).pressKeyCode(AndroidKeyCode.HOME);
((AndroidDriver) appiumDriver).pressKeyCode(AndroidKeyCode.KEYCODE_APP_SWITCH);
appiumDriver.findElementById(“com.android.systemui:id/recent_item”).click();

1 Like