I want to get all the tasks that are running in android.I found getRunningTasks in ActivityManager but from android-5.0 the getRunningTasks may not give all the tasks (in my case it's give the home screen and my application).
In addition is it possible to find the task that the user is currently interacting with?
Any help would be greatly appreciated.
Thanks.
Edit: I am using the following piece of code.But it's giving me only one process (that's my app).Even if i open other apps it's not showing them.I am running this on One Plus2.
@Override
protected void onHandleIntent(Intent intent) {
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
getRunningApps();
}
}, 0, 1000);//put here time 1000 milliseconds=1 second
}
public void getRunningApps() {
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> recentTasks = activityManager.getRunningAppProcesses();
for (int i = 0; i < recentTasks.size(); i++)
{
Log.d("Executed app", "Application executed : " +recentTasks.get(i).pkgList[0]+ "\t\t ID: "+recentTasks.get(i).pid+"");
}
}