Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get info about all running activities in android programmatically?

Tags:

android

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?

like image 903
kiran Avatar asked Mar 16 '12 11:03

kiran


People also ask

How do I see all tasks on Android?

Use getRunningAppProcesses , which will return a list of RunningAppProcessInfo objects that will give you some data about each running app.

What is the Mainactivity?

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.

What is Flag_activity_new_task in Android?

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() .


1 Answers

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.

like image 82
KK_07k11A0585 Avatar answered Oct 15 '22 19:10

KK_07k11A0585