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
Here is my solution:
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}
Be careful!!The last ID is not the PID of the process!! If you want to get the PID of the process I used the following command :
mLogcatProc = Runtime.getRuntime().exec(new String[] {"ps"});
Read the result finding the application name and then split to obtain PID process.