Android - Kill All Logout Actions

When the user removes the "Logout" in my application, I would like them to be moved to the "Logon" and destroy all other running or paused actions in my application.

My application uses general settings to bypass the "Login" action at startup if the user has previously logged in. Therefore, FLAG_ACTIVITY_CLEAR_TOP will not work in this case, because the input activity will be at the top of the activity stack when the user is delivered there.

+5
source share
3 answers

You can use BroadcastReceiver to listen to the kill signal in your other actions.

http://developer.android.com/reference/android/content/BroadcastReceiver.html

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);

.

Intent intent = new Intent("CLOSE_ALL");
this.sendBroadcast(intent);
+12

API 11+ Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK :

Intent intent = new Intent(this, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

.

+8

FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_CLEAR_TASK ( API 11+):

If specified in the Intent passed to Context.startActivity (), this flag will cause any existing task to be associated with the activity to be cleaned up before the action begins. That is, the activity becomes the new root of the empty task, and all the old actions are completed. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

+2
source

All Articles