Checks whether the activity is at the top of the stack of the current task.

Source: Internet
Author: User

APIS related to the internal status of the Android system:


Activitymanager:

Activitymanager = (activitymanager) This. getsystemservice (activity_service)


What information is this bit:

Configurationinfo = activitymanager. getdeviceconfigurationinfo ();


Obtain the memory status of a process:

Debug. memoryinfo [] processmemoryinfo = activitymanager. getprocessmemoryinfo (processids );

Obtain information about the currently running service:

List <runningserviceinfo> runningserviceinfos = activitymanager. getrunningservices (maxvalue );


Obtain information about the currently running task:
List <runningtaskinfo> runningtaskinfos = activitymanager. getrunningtasks (maxvalue );

Among them, the topactivity of runningtaskinfos is the active activity of the current task.

In the task queue returned by getrunningtasks (), the system sorts the tasks according to their activity level, and the more active the tasks are. The first is the active task.


/**

* Checks whether an activityupdate is at the top of the stack of the current task.

*/

Public
Boolean istopactivy (string comment name ){
Activitymanager manager = (activitymanager) Context. getsystemservice (activity_service );
List <runningtaskinfo> runningtaskinfos = manager. getrunningtasks (1 );
String cmpnametemp = NULL;


If (null! = Runningtaskinfos ){


Cmpnametemp = (runningtaskinfos. Get (0). topactivity). tostring );


Log. E ("cmpname", "cmpname:" + cmpname );


}


If (null = cmpnametemp) return false;
Return cmpnametemp. Equals (parameter name );

}


Finally, add the required permissions to the application:

<Uses-Permission Android: Name = "android. Permission. get_tasks"/>

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.