When a user taps "Logout" within my application, I would like them to be taken to the "Login" activity and kill all other running or paused activities within my application.
My application is using Shared Preferences to bypass the "Login" activity on launch if the user has logged in previously. Therefore, FLAG_ACTIVITY_CLEAR_TOP will not work in this case, because the Login activity will be at the top of the activity stack when the user is taken there.
exit(); or finish(); it exit full application or all activity.
In Android we can change the default behaviour of the any activity like keypress, back button press, swap left swap right, to do Disable Back Press we need to override default functionality of onBackPressed() or onKeyDown() method in Activity class.
You can auto logout your session using the AlarmManager class. Here is the method you should call after the login. Then the BootCompletedIntentReceiver broadcast receiver will be triggered at 19.59. You can write Your action in Broadcast receiver.
In the second activity, the back button at the top left can be used to go back to the previous activity.
You could use a BroadcastReceiver to listen for a "kill signal" in your other activities
http://developer.android.com/reference/android/content/BroadcastReceiver.html
In your Activities you register a BroadcastReceiver
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("CLOSE_ALL");
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// close activity
}
};
registerReceiver(broadcastReceiver, intentFilter);
Then you just send a broadcast from anywhere in your app
Intent intent = new Intent("CLOSE_ALL");
this.sendBroadcast(intent);
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