Determine if the app is over

Source: Internet
Author: User

Today, when doing GCM offline push, we need to determine if the app is online.

Push offline messages If you don't push them online

Here is the technology of whether the app is online

From the Internet to find a way to modify the appropriate

Private Boolean Isrunningforeground (context context) {

Activitymanager am = (activitymanager) context.getsystemservice (Context.activity_service);

ComponentName cn = Am.getrunningtasks (1). Get (0). topactivity;

String currentpackagename = Cn.getpackagename ();

if (! Textutils.isempty (currentpackagename) && currentpackagename.equals ("Com.uvisioncctv.FirstStart"))// This is my package name, the main package name.

{

return true;

}

return false;

}

OK, test Pass

After I have repeatedly tested found that the app will not end immediately after exiting, need to wait 3-5 seconds before the end

I don't know what the reason is, I hope the gods can share the experience and tell


This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1429159

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.