How to get a list of the activity history stack?
So is there a way to do that using a function from the SDK?
No, sorry.
Would it be possible to listen to "start/finish activity" events with some kind of receiver to a specific app (mine) and keep track of the stack history?
You can use registerActivityLifecycleCallbacks()
on Application
, if you are only going to support API Level 14 and higher (a.k.a., Android 4.0+).
Using ADB commands:
adb shell dumpsys activity activities # displays list of activities in back stack
adb shell dumpsys activity process # displays list process in back stack
adb shell dumpsys activity intents # displays list of pending intents in back stack
adb shell dumpsys activity broadcast # displays list of broadcast in back stack
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<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();
}