简体   繁体   English

活动堆栈

[英]activities stack

有没有办法在调试或正常运行的某个时刻对活动堆栈进行虚拟化?

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. 这有一个pkgLst方法可能会有所帮助。

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. Activity提供了getCallingActivity()方法,您可以按照之前的建议添加到onPause和onResume中的日志中。

There is also if ( isChild() ) getParent(); 还有if ( isChild() ) getParent(); for embedded activities. 用于嵌入式活动。

On the emulator or in a rooted phone you can use the dumpsys shell command 在模拟器或root电话中,您可以使用dumpsys shell命令

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 要仅提取任务,我使用grep

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

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

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() . 对于您自己的应用程序,您可以通过将自己推送到onResume()自己的堆栈数据结构并在onPause()从该堆栈中弹出自己来自行跟踪。

我认为没有直接的方法,但是一种方法是将日志放在create / pause / resume / destroy / etc上的所有回调函数中并查看调用(例如:Log.d())。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM