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