What do you call the main launch activity from another activity?

In my program, I have an activity that starts when the application opens. If I open a couple more events, how can I return to the main activity? In the intent filter, the activity name is "android.intent.action.MAIN", and this will not allow me to call startActivity () on it. What should I do?

+3
source share
2 answers

You can do this with Intent .

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

This intention will launch the launch application that the user defined. Be careful with this because it will look as if your application did not expect this, your application will fail.

+5
Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

, : MainActivity > Activity1 > Activity2 > Activity3, 1 2 MainActivity

+4

All Articles