How to get a list of the activity history stack?

后端 未结 4 1596
北海茫月
北海茫月 2020-12-08 10:13

I\'m struggling with an issue in my app. I\'d like to provide a way to list the history of the previous opened activities.

I think there are two potential solutions

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 11:02

    Using ADB commands:

    1. adb shell dumpsys activity activities  -> displays list of activities in back stack
    
    2. adb shell dumpsys activity process  -> displays list process in back stack
    
    3. adb shell dumpsys activity intents  -> displays list of pending intents in back stack
    
    4. adb shell dumpsys activity broadcast  -> displays list of broadcast in back stack
    
    5. adb shell dumpsys activity services  -> displays list of services running in back stack
    

    Using Activity manager:

     ActivityManager m = (ActivityManager) ctx.getSystemService( ctx.ACTIVITY_SERVICE );
        List runningTaskInfoList =  m.getRunningTasks(10);
        Iterator 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();
    }
    

提交回复
热议问题