Want to take application back in foreground

Hi,

I have 2 applications.

  • I want to perform some activity on first application.
  • Move the first application in background.
  • Launch second application.
  • Perform some activity on second application.
  • Get first application in foreground and perform activity on that.

Please find the code here.

    driver.runAppInBackground(0);
    	        Thread.sleep(1000);
    	        driver.startActivity("com.headcode.ourgroceries","com.headcode.ourgroceries.android.ListsActivity");
    	        Thread.sleep(1000);
    	        driver.runAppInBackground(0);
    	        Thread.sleep(1000); 
driver.startActivity("com.whatsapp", "com.whatsapp.RegisterPhone");
    driver.findElement(By.id("com.whatsapp:id/registration_submit")).click();

I’m getting this error:

com.headcode.ourgroceries/.android.ListsActivity never started. Current: com.whatsapp/.RegisterPhone
e[36minfoe[39m: e[37m<-- POST /wd/hub/session/12eb15d2-dd48-498a-b67c-7b6a101b1560/appium/app/background e[39me[31m500e[39me[90m 31290.483 ms - 388e[39m e[90me[39m
An unknown server-side error occurred while processing the command. (Original error: com.headcode.ourgroceries/.android.ListsActivity never started. Current: com.whatsapp/.RegisterPhone) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31.30 seconds
Build info: version: ‘2.46.0’, revision: ‘61506a4624b13675f24581e453592342b7485d71’, time: ‘2015-06-04 10:22:50’
System info: host: ‘LENOVO’, ip: ‘180.215.174.241’, os.name: ‘Windows 8’, os.arch: ‘x86’, os.version: ‘6.2’, java.version: ‘1.8.0_45’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.whatsapp, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=emulator-5554, platform=LINUX, appActivity=com.whatsapp.Main, fullreset=false, desired={appActivity=com.whatsapp.Main, fullreset=false, appPackage=com.whatsapp, newCommandTimeout=60000, autoLaunch=true, platformVersion=4.3.1, platformName=Android, deviceName=emulator-5554}, newCommandTimeout=60000, autoLaunch=true, platformVersion=4.3.1, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: 12eb15d2-dd48-498a-b67c-7b6a101b1560

Hi Mashkurm,

You can use adb to switch between activities. here you can find the details. Idea is to identify the main activity name of you apk and then use adb command to control your app.

Thanks,
Donald