我有一个带有 Activity 堆栈A-> B-> C-> D-> E的应用程序。现在在 Activity E上,我想知道我从中导航的堆栈 Activity 。我怎么找到这个?

最佳答案

下面的代码可用于提取所有任务以及后台堆栈中每个任务中的最高 Activity

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();
}

关于android - 如何在Android应用程序中查找后退堆栈 Activity ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7992563/

10-09 03:09