Appium 1.6.5 - how to start android activity with driver.startActivity(activity);


I am using latest appium 1.6.5 and java - client : 5.0.0-BETA8
I was previously using driver.startActivity using app package and app activity (where were string arguments) and it was working as expected.

Now with above version - looks like all startActivity has been deprecated except driver.startActivity(appActivity) - where appActivity is of type Activity.

I have activity of type string and it throws class cast exception when I try to cast string to Activity.
How do i pass the appactivity of type activity ?



        Activity activity = new Activity("app package goes here", "app activity goes here");
        activity.setAppWaitPackage("app wait package goes here");
        activity.setAppWaitActivity("app wait activity goes here");
        ((AndroidDriver) driver).startActivity(activity);


Can you please explain with example? suppose I am switching app to messaging app. What would be my code ?


Thanks, It worked for me


Hello @Aleksei
I am trying to understand this code
Activity activity = new Activity(“app package goes here”, “app activity goes here”);
So the above we pass the new activity package name?

If we have passed the new app packagename activity name then why we need the below
activity.setAppWaitPackage(“app wait package goes here”);
activity.setAppWaitActivity(“app wait activity goes here”);

What does the below do?

How does the app return back to my old package?



@vsharma it is only calls needed APP in needed activity. nothing more.

About stopApp ->

     * Sets the stop app value.
     * @param stopApp The stop app value.
     * @return self reference
    public Activity setStopApp(boolean stopApp) {
        this.stopApp = stopApp;
        return this;

to return just close app you opened or:

((AndroidDriver) driver).runAppInBackground(1);

should restore back your original app under test.


Thank You @Aleksei I shall try this
Do you have your own Blog :slight_smile: or videos you created for Beginners…