After I get a list of running tasks, I can get almost any information I would need. However, I couldn't find how to get how long the task has been running. I even tried the metaData
Bundle
that gets returned with the ActivityInfo, but that is null even though I explicitly request it. Is this possible at all?
I get the list of tasks as follows:
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningTaskInfo> list = am.getRunningTasks(100);
PackageManager pm = getPackageManager();
for (RunningTaskInfo thisInfo : list) {
try {
ComponentName componentName = thisInfo.baseActivity;
ActivityInfo activityInfo = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA);
// this is null for some reason
Bundle metaData = activityInfo.applicationInfo.metaData;
} catch (NameNotFoundException e) {
Log.e("AppChecker", "Oops");
e.printStackTrace();
}
}