Skip to content Skip to sidebar Skip to footer

How To Find Back Stack Activities In An Android Application?

I have an application with activities back stack A -> B -> C -> D -> E. Now at activity E, I want to know the back stack activities that I navigated from. How do I find

Solution 1:

The code below can be used to extract all the tasks and the top activity within each task in the back stack

ActivityManagerm= (ActivityManager) ctx.getSystemService( ctx.ACTIVITY_SERVICE );
List<RunningTaskInfo> runningTaskInfoList =  m.getRunningTasks(10);
Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator();
while(itr.hasNext()){
    RunningTaskInforunningTaskInfo= (RunningTaskInfo)itr.next();
    intid= runningTaskInfo.id;
    CharSequence desc= runningTaskInfo.description;
    intnumOfActivities= runningTaskInfo.numActivities;
    StringtopActivity= runningTaskInfo.topActivity.getShortClassName();
}

Solution 2:

You can use "adb shell dumpsys activity activities" command

for reference http://www.onsandroid.com/2015/01/find-back-stack-activities-in-android.html

Solution 3:

Solution 4:

I'm not sure i get it well...You want to go back to the previous activity ? If so, finish the current activity you'll get back to the previous one.

Solution 5:

actually, you can get the task id from the runningtaskinfo using getRunningTasks and then, get the recenttaskinfo using getRecentTasks by compare the task id. now you can restart that activity using startactivity, with the baseintent in the recenttaskinfo.

Post a Comment for "How To Find Back Stack Activities In An Android Application?"