2

我一直在尝试自学 Android,并且刚刚了解到我一直Activity在我的代码中创建相同的多个实例。从概念上讲,我知道它就在那里,但是有什么工具(例如 DDMS)可以用来查看我创建了多个实例吗?

这也将帮助我了解我的Intent标志实验是否有效。

4

2 回答 2

4

您可以使用以下命令可视化当前活动堆栈:

adb shell dumpsys activity

它会向您显示如下内容:

 Running activities (most recent first):
    TaskRecord{40538e50 #164 A com.xxx}
      Run #3: HistoryRecord{xxxx com.xxx/.activities/xxx}
      Run #2: HistoryRecord{xxx com.xxx/.activities/xxx}
      Run #1: HistoryRecord{xxx com.xxx/.activities/xxx}
    TaskRecord{40a89008 #48 I com.android.htcdialer/.Dialer}
      Run #0: HistoryRecord{409d91d0 com.android.htcdialer/.Dialer}

一些资源:

于 2012-05-16T12:27:06.183 回答
0
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {  
            // Activity was brought to front and not created,  
            // Thus finishing this will get us to the last viewed activity  
            finish();  
            return;  
        }  
于 2012-05-16T13:33:23.103 回答