Complete all but one

When I use this method, I return to the login page, but I can still press the return button, and it returns me to the previous action. why doesn't he close other actions?

public void restartApplication() {
        Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);   
    }

Is there a way to complete all actions except login activity? or restart the whole application?

+5
source share
3 answers

I think that because of the package manager, activity starts with a new history stack.

Try using the activity name instead of getting it from the package manager. For instance.

Intent i = new Intent(getApplicationContext(), LoginActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
+3
source

Try adding finish();after startActivity(i);.

0
source

.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); inplace of intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Intent intent = new Intent(getApplicationContext(),
        yourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity(intent);
0

All Articles