Reputation: 33
My application scenario looks like this :
MainActivity > TaskActivity > TaskActivity > TaskActivity > ... > MainActivity
Each TaskActivity
Previous activities do not need to be kept in back stack. Actually I want them not to be kept, given the fact that a lot of activities can be launched (causing problems of memory consumption = frequent OutOfMemory exception) and I don't allow the user to go back to previous activities.
Here is my TaskActivity :
public class TaskActivity extends FragmentActivity {
private void launchNextTask(Task nextTask) {
Intent intent = new Intent(TaskActivity.this, TaskActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(TASK_KEY, nextTask);
startActivity(intent);
}
}
All my activites have transition animations :
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
It was working fine until I added the NEW_TASK and CLEAR_TASK flags in the intent.
So this code is working fine, I can see GC freeing memory each time I launch a TaskActivity, except activity transitions are not working anymore.
Question is : Which intent flags could I use to clear back stack each time a TaskActivity is launched, and still keep activity transitions?
Upvotes: 2
Views: 1644
Reputation: 20023
Change your code to
public class TaskActivity extends FragmentActivity {
private void launchNextTask(Task nextTask) {
Intent intent = new Intent(TaskActivity.this, TaskActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(TASK_KEY, nextTask);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
}
And it should fix your issue.
Upvotes: 1