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

Hi,
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 ?

@PavithraNavaneeth

        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");
        activity.setStopApp(false);
        ((AndroidDriver) driver).startActivity(activity);
2 Likes

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?
activity.setStopApp(false);

How does the app return back to my old package?

Thanks
VS

@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ā€¦

I get however java.lang.ClassCastException.

java.lang.ClassCastException: class io.appium.java_client.AppiumDriver cannot be cast to class io.appium.java_client.android.AndroidDriver (io.appium.java_client.AppiumDriver and io.appium.java_client.android.AndroidDriver are in unnamed module of loader ā€˜appā€™)