See Android recent task executed by the user

int numberOfTasks = 1;
ActivityManager m = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
//Get some number of running tasks and grab the first one.  getRunningTasks returns newest to oldest
RunningTaskInfo task = m.getRunningTasks(numberOfTasks).get(0);

//Build output
String output  = "the last application you've executed is '"+task.id+"' and the PID is '"+task.baseActivity.toShortString()+"'";

getRunningTasks

RunningTaskInfo

Leave a Comment