I have tricky scenario, where you perform at some event some view of your native application. In subsequent step you switch to some other activity. And after performing some activity on other activity you moved back to your orignal app with the last activity. So is there any way to do so? I tried to launch other activity from my main application, but while moving back to orignal app it lost context.
It depends upon how you started the android settings app. If you gave yourself access to adb to launch the intent from there, you could do something similar to get back to your app.
Alternatively, you can use the appium driver to bring up your app:
You can use adb shell am start -n com.package.name/com.package.name.ActivityName . You can find out more here
Other than adb there is a solution with selendroid(if you are ok with that). BackgroundApp() and resumeApp() functions to switch between different AUT. here you can get the sample code and problem description.
@willosser : i tried by saving activity name before switching other activity,
String lastActivityName = driver.getCurrentActivity();
driver.startActivity(<pkg 1>,<activity 1>);
driver.startActivity(lastPkg,lastActivity) ; – so basically it launched activity but its just like you run adb shell am start -n com.package.name/com.package.name.ActivityName , which does not have any info about last context. @Donald: I think the first approach will not work because adb does not have any info about your last activity. Well i did not check with selendroid. so I will try and let you know.
@Priyank_Shah, getCurrentActivity does not return the fully qualified activity. i.e. it returns com.package.name.Activity.Name instead of com.package.name/com.package.name.ActivityName, using your example.
You likely passed the package and activity name to the Appium server as capabilities, so you should be able to use these values again to restart it. It ends up calling that adb command as you noticed, so if you want to call it that way as Donald suggested, that should also work.
I tried this with android activity manager and it worked for me.
Use apktool to extract contents of apk with command java -jar d -f aut.apk
locate AndroidManifest.xml file.
The AndroidManifest.xml file can be opened in any text editor. I recommend one with syntax highlighting.
Search for the Keyword “LAUNCHER” and note down the activity name associated with it.This activity should be started when the user taps the application icon in the Launcher (handles specific intent Category called LAUNCHER).
Note : Please separate package name and main activity name in command with a forward slash followed by dot.
If you see a warning message like “Warning: Activity not started, its current task has been brought to the front” that means you have done it- congratulations .
In addition with this people can run adb shell am start -a android.intent.action.MAIN -c android.intent.category.HOME to send the app in backgroud(many people asked this question before)