See Android recent task executed by the user

后端 未结 3 1279
广开言路
广开言路 2020-11-30 08:39

I would like to watch the recent task of my android phone. I was trying some code from internet but non of them work properly. I just want to get the PID and Name of the las

3条回答
  •  無奈伤痛
    2020-11-30 08:50

    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

提交回复
热议问题