I am developing an application in which I am following a hierarchy, there is an option from which user can Login, after this I am finishing the Login Activity. Now once user gets logged in I am taking him to a new Activity suppose "Activity A". From this activity again a new Activity is being starting called "Activity B" without finishing the "Activity A". And finally there is a last Activity named as "Activity C" which gets started from "Activity B" without finishing "Activity B". So currently all of the three activities are is stack.
Now, Every screen or Activity has an option called Logout, If the user is on "Activity A", I am just finishing the Activity and Opening Login Activity. For this scenario its working fine but Once I am switching to "Activity B" or Activity C" and then if user press Logout what should I do to remove all of the Activities in stack and also I have to open the Login Activity as I have finished it while successful login.
I know there is a FLAG in API 11 by using which we can clear all the activities in stack :-
Intent i = new Intent(mContext, LoginGateway.class);
// set the new task and clear flags
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(i);
But I am supporting it from API 8. I want a solution which I can use for API 8 onward, please help me to find out that. Any help would be appreciable. Thank You.
Intent intent = new Intent(activity, LoginGateway.class);
ComponentName cn = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
activity.startActivity(mainIntent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With