In my app I\'ve a several Activities that inherit from one BaseActivity.
My application receive push notification with GCMBaseIntentService
I need to
It seems that PackageManager.queryBroadcastReceivers() returns all receivers declared in application manifests matching a given Intent.
Note however that this will not include receivers registered with Context.registerReceiver(); there is currently no way to get information about those.
You can use the following code in onReceive() to determine if the application/activity is running or not
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List taskInfo = am.getRunningTasks(1);
Log.d("current task :", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClass().getSimpleName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
if(componentInfo.getPackageName().equalsIgnoreCase("your.package.name")){
//Activity in foreground, broadcast intent
}
else{
//Activity Not Running
//Generate Notification
}