Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find back stack activities in an android application?

Tags:

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 this??

like image 990
azzits Avatar asked Nov 03 '11 09:11

azzits


People also ask

How do I view Backstacks on Android?

1): View->Tool Windows->Android. Then on the left hand side select the System Information Icon and from it's drop down select 'Graphics State'. This will dump show a lot of information, but if you scroll down to 'View hierarchy:' you will see the current stack of views i.e. the 'Back Stack'.

How do I get my activity back on Android?

If you wants to go back from one activity to another activity, This example demonstrate about how to go back to previous activity in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

How can I see activity stack?

Just open the perspective Windows->Open Perspective-> Hierarchy View In the list you can see the all the connected devices and emulators and the activity stack. And in addition in the tree view you can see much more information about the view itself.


2 Answers

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

ActivityManager m = (ActivityManager) ctx.getSystemService( ctx.ACTIVITY_SERVICE );
List<RunningTaskInfo> runningTaskInfoList =  m.getRunningTasks(10);
Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator();
while(itr.hasNext()){
    RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next();
    int id = runningTaskInfo.id;
    CharSequence desc= runningTaskInfo.description;
    int numOfActivities = runningTaskInfo.numActivities;
    String topActivity = runningTaskInfo.topActivity.getShortClassName();
}
like image 174
Rajdeep Dua Avatar answered Oct 05 '22 06:10

Rajdeep Dua


You can use "adb shell dumpsys activity activities" command

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

like image 45
suresh Avatar answered Oct 05 '22 07:10

suresh