At some point you'll find yourself needing to get information about the activities running in a certain task.
There's an easy way of getting a list of running tasks from the activitymanager service.
You can request a maximum number of tasks running on the phone, and by default, the currently active task is returned first.
Once you have that you can get a componentname object by requesting the topactivity from your list.
Here's an example.
View Source
Print?
01 |
// get a list of running processes and iterate through them |
02 |
ActivityManager am = (ActivityManager) this |
03 |
.getSystemService(ACTIVITY_SERVICE); |
05 |
// get the info from the currently running task |
06 |
List<ACTIVITYMANAGER.RUNNINGTASKINFO> taskInfo = am.getRunningTasks(1); |
08 |
Log.d( "current task :" , "CURRENT Activity ::" |
09 |
+ taskInfo.get(0).topActivity.getClassName()); |
11 |
ComponentName componentInfo = taskInfo.get(0).topActivity; |
14 |
componentInfo.getPackageName(); |
Please ignore the closing tag. The Code formatter I'm using sucks !.
Post: http://qtcstation.com/2011/01/getting-info-about-your-currently-running-activities/