Source: http://stackoverflow.com/questions/9736680/how-to-get-info-about-all-running-activities-in-android
ActivityManager m = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE );
List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10);
Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator();
while(itr.hasNext())
{
RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next();
int id = runningTaskInfo.id;
CharSequence desc = runningTaskInfo.description;
String topActivity = runningTaskInfo.topActivity.getShortClassName();
int numOfActivities = runningTaskInfo.numActivities;
}
**Note: ** you have to specify **android.permission.GET_TASKS**
permission in Manifest file
This method is deprecated with Lolipop, because of its shift towards document centric task management, which could leak personal information. – joecks Jan 25 '15 at 12:12
Source: http://stackoverflow.com/questions/22903604/get-all-apps-running-time-on-android
You can get a list of each service's start time by using ActivityManager.RunningServiceInfo.activeSince, described here. Here's a snippet that retrieves the times for all service processes.
ActivityManager activityManager =
(ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services =
activityManager.getRunningServices(Integer.MAX_VALUE);
long currentMillis = Calendar.getInstance().getTimeInMillis();
Calendar cal = Calendar.getInstance();
for (ActivityManager.RunningServiceInfo info : services) {
cal.setTimeInMillis(currentMillis-info.activeSince);
Log.i(TAG, String.format("Process %s with component %s
has been running since %s (%d milliseconds)",
info.process, info.service.getClassName(),
cal.getTime().toString(), info.activeSince));
}
The Log statement is logging the start time and how any milliseconds the background service processes have been running. You'll want to use the same method calls that the Log statement is using to do something with the data. – scottt Apr 7 '14 at 13:37
i hope this may help you.