Android Instrumentaion: How do I return to a previously launched activity?

I am currently running automation tests using an application that uses multiple Activity to display each screen.

Is there a way to revert to a previously launched action while testing the toolkit? Currently, when I use sendKeyDownUpSync (KeyEvent.KEYCODE_BACK); this causes my test to exit, rather than returning to the previous action.

Any help with this is much appreciated.

Gin

+3
source share
4 answers

You can try calling the method finish()for the operation you want to close.

+6
source

. finish() :) , , Android Runtime .

+1

You can also use the method for this. Thia is not recommended, but the code below may be useful to you.

public void launchActivityCurrent() {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        System.out.println("Inside Launch  Activity current");
                      intent.setClassName("YourpackageName","Activity you want to launch");
                      For ex:
        intent.setClassName("com.android.mms","com.android.mms.ui.ConversationList");
        Context c = currentContext();
        c.startActivity(intent);
    }

I use robotium and I do not call the toolkit again, so I use this method to run in application activity. I hope this is also useful for you.

+1
source

Have you tried onBackPressed()?
See Back to previous event for more details.

0
source

Source: https://habr.com/ru/post/1733607/


All Articles