Getting info about your currently running activities

Source: Internet
Author: User
Tags closing tag

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);
04   
05         // get the info from the currently running task
06         List<ACTIVITYMANAGER.RUNNINGTASKINFO> taskInfo = am.getRunningTasks(1);
07   
08         Log.d("current task :", "CURRENT Activity ::"
09                 + taskInfo.get(0).topActivity.getClassName());
10   
11         ComponentName componentInfo = taskInfo.get(0).topActivity;
12   
13 ...
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.