In android, you get info about running activities by watching the Logcat.
For example if you open camera, it is logged in the Logcat.
Is there a way to get that info programmatically?
Use getRunningAppProcesses , which will return a list of RunningAppProcessInfo objects that will give you some data about each running app.
Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With