In my app I\'ve a several Activities that inherit from one BaseActivity.
My application receive push notification with GCMBaseIntentService
I need to
You can check whether application is in background or foreground using this code :
public String isApplicationSentToBackground(final Context context) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return "false";
}
}
return "true";
}
If it returns "true" then show notification else show dialog box.
When I debug the context.getPackageManager().queryBroadcastReceivers(pushReceivedIntent, 0).size() always equals to 0.
For this don't pass 0 in notify().Instead pass "Calendar.getInstance().getTimeInMillis()" value.This will show all the notifications based on time.
Hope this will help you.