In my application I have push notification integrated with GCM
. Its working fine whenever notification comes its appearing. But push notification come even when
Do something like this to check whether you app is in foreground or not by calling below method and depending on returning value true or false do your rest of work
public boolean checkApp(){
ActivityManager am = (ActivityManager) this
.getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equalsIgnoreCase("YourPackage")) {
return true;
} else {
return false;
}
}