2020年12月23日星期三

Android: Clear current activity task when creating a new activity task with different taskAffinity

Let's say I have to set taskAffinity to empty string for all the activity. Let's say the top activity of current activity task is HomeActivity(this is the activity user sees after logging in). When user logs out, I use below lines to log user out(basically re-presenting the login page and I want to clear all the previous activities in the stack):

...  (other stuff like clear data)  Intent loginIntent = new Intent(LoginActivity.class);  loginIntent.addFlags(FLAG_ACTIVITY_NEW_TASK);  loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);  startActivity(loginIntent);  ...  

Since I set taskAffinity to empty string for all the activity, which means all the activities do not belong to any affinity. If I use FLAG_ACTIVITY_NEW_TASK when starting a new activity, a new activity task is created instead of reusing the current one. FLAG_ACTIVITY_CLEAR_TASK is just to clear the new tasks instead of the current one.

So, there actually will have two activity tasks running: the original one(with HomeActivity) and the new one(with LoginActivity). I wonder if there are any ways to delete the current activity task when starting a new activity task.

https://stackoverflow.com/questions/65432766/android-clear-current-activity-task-when-creating-a-new-activity-task-with-diff December 24, 2020 at 09:02AM

没有评论:

发表评论