Reputation: 1851
I googled but not find helpful information about this. If I open app and go through these activities A-B-C-D, app has 4 activity in back stack. Android can kill process, what he actually does, after restoring app I see activity D, so how I can handle this behavior, how to check how many real activity I have in back stack.
I tried:
ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(10);
Log.d("myTag",taskList.get(taskList.size()-1).numActivities+"");
Or
ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(10);
if(taskList.get(0).numActivities == 1 && taskList.get(0).topActivity.getClassName().equals(this.getClass().getName())) {
Log.i(TAG, "This is last activity in the stack");
}
But it show the same number before and after killing process.
I want to redirect user to actviity A if my app was terminated, and back pressed event will close app.
Upvotes: 0
Views: 145
Reputation: 1812
You should handle with this using onSavedInstanceState.
The guideline says:
The two ways in which an activity returns to user focus with its state intact: either the activity is destroyed, then recreated and the activity must restore the previously saved state, or the activity is stopped, then resumed and the activity state remains intact.
So, you should save the instance state and restore this at onRestoreInstanceState then you can do what you want based on previous state of your activity.
Check this link for reference: http://developer.android.com/guide/components/activities.html#ConfigurationChanges
Hope that it helps.
Upvotes: 2