0

i know there had been a lot of question already on stack overflow about this topic, but nothing is working for me. what i want to achieve is i want to clear all the activity back stack on a particular method call.

lets say i have one entry point in my app that is login() method. now i am calling this method from five different activities. after login is always the one screen will be shown. now what i want to achieve is regardless of from where the login() method was called if login is successful then user should go to next activity (activity2) and on double time back press of that activity (activity 2) the user should be out of the app.That is i want my activity back stack to get cleared on success of login() method.

this is what i am doing on success of login, but its not helping.

Intent i = new Intent(context, DrawerActivity.class);
                                           i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
((Activity)context).finish();

How to do that?

thanks in advance :)

Newbiee
  • 592
  • 6
  • 22

2 Answers2

0

If User successfully logins then open your second main activity using below flags:

Intent intent = new Intent(this, ActivitySecond.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();
Er. Kaushik Kajavadara
  • 1,657
  • 2
  • 16
  • 37
0
Intent intent = new Intent(this, Example.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81