Intent flags to Login page redirect, killing previous Activities

Posted by Christopher Francisco on Stack Overflow See other posts from Stack Overflow or by Christopher Francisco
Published on 2014-08-19T04:16:26Z Indexed on 2014/08/19 4:20 UTC
Read the original article Hit count: 178

Filed under:
|

Basically I have a Service that at some points it will sync with the network in order to check if the token is still valid. if it isn't, it should redirect to the login screen (from the service) and if the user press the back button, it should NOT show the previous Activity but instead exit the app.

I'm not asking how to hack onBackPressed, I already know how to do it. I'm asking how to accomplish this using the intent flags.

So far I have tried the following:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

Using the FLAG_ACTIVITY_NEW_TASK is mandatory because I'm calling startActivity() from a service (or at least thrown exception told me so), and using FLAG_ACTIVITY_CLEAR_TOP cause it was supposed to remove all previous activities from the stack, leaving only the new one.

The issue is if I press back, I am still able to go to the previous Activity, which makes me think the combination of both flags are clearing the activities in the NEW task, not in the previous one

I might be wrong on the reason, but it doesn't work. Any help will be appreciated, thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about android-intent