activities stack

前端 未结 4 1562
旧时难觅i
旧时难觅i 2020-12-31 08:30

Is there a way to vizualise the activity stack, at some moment during debug, or normal run ?

相关标签:
4条回答
  • 2020-12-31 09:09

    Not that I am aware of. For within your own application, you can track this yourself by pushing yourself onto your own stack data structure in onResume() and popping yourself off of that stack in onPause().

    0 讨论(0)
  • 2020-12-31 09:21

    On the emulator or in a rooted phone you can use the dumpsys shell command

    adb shell dumpsys activity
    

    which outputs the existing tasks. Here a little snippet

    Running activities (most recent first):
    TaskRecord{407d8a30 #6 A com.actionbarsherlock.sample.demos}
      Run #2: HistoryRecord{40792ec8 com.actionbarsherlock.sample.demos/.ActionItems}
      Run #1: HistoryRecord{40735008 com.actionbarsherlock.sample.demos/.SampleList}
    TaskRecord{406de0b8 #2 A com.android.launcher}
      Run #0: HistoryRecord{405802c8 com.android.launcher/com.android.launcher2.Launcher}
    

    You can even see the intent that started the activity

    TaskRecord{407d8a30 #6 A com.actionbarsherlock.sample.demos}
    clearOnBackground=false numActivities=2 rootWasReset=true
    affinity=com.actionbarsherlock.sample.demos
    intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.actionbarsherlock.sample.demos/.SampleList}
    realActivity=com.actionbarsherlock.sample.demos/.SampleList
    lastActiveTime=1492068 (inactive for 2s)
    * Hist #2: HistoryRecord{40792ec8 com.actionbarsherlock.sample.demos/.ActionItems}
        packageName=com.actionbarsherlock.sample.demos processName=com.actionbarsherlock.sample.demos
        launchedFromUid=10040 app=ProcessRecord{40650b68 1840:com.actionbarsherlock.sample.demos/10040}
        Intent { cmp=com.actionbarsherlock.sample.demos/.ActionItems }
    

    To extract only the Tasks, I use grep

    adb shell dumpsys activity | grep "Running activities" -A 10
    

    Source: http://www.slideshare.net/RanNachmany/manipulating-android-tasks-and-back-stack

    0 讨论(0)
  • 2020-12-31 09:23

    There is no direct way i think, but a way is to put logs in all call backs lik on create/pause/resume/destroy/etc and see the calls(Ex:Log.d()).

    0 讨论(0)
  • 2020-12-31 09:27

    You can get some useful information with the activity manager.

    ActivityManager         manager = (ActivityManager)getApplication().getSystemService( Activity.ACTIVITY_SERVICE );
    

    This will show you the top, bottom and size of the stack, and description may be useful. You will have to search the running tasks to find the current activity.

    RunningTaskInfo         task = manager.getRunningTasks( 10 ).get( 0 );
    task.baseActivity();
    task.numActivities();
    task.topActivity();
    task.description();
    

    This has a pkgLst method that may be helpful.

    RunningAppProcessInfo   app = manager.getRunningAppProcesses().get( 0 );
    app.pkgList();
    

    Not as useful or straightforward as you were hoping for, but it might help.

    Activity provides the getCallingActivity() method that you could add to logs in onPause and onResume as suggested before.

    There is also if ( isChild() ) getParent(); for embedded activities.

    0 讨论(0)
提交回复
热议问题