I am developing an Application which is using Push Notification (GCM) ,This application is receiving Push Noifications when app is running ,but when I forced stopped it from Settings ->apps->MyApp(click on it) and click on force stop ,then it is not receiving Push Notifications. I have tested same with WhatsApp it is receiving Push Notifications when I force stop it . So how can I implement same with my application .
Note : In code I am receiving PushNotifications in a sub class of WakefulBroadcastReceiver ,I have registered it statically in manifest even it is not called when application force stops.
public class GCM_Receiver extends WakefulBroadcastReceiver {
//Processes Gcm message .
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "GCM_Receiver", Toast.LENGTH_LONG).show();
ComponentName comp = new ComponentName(context.getPackageName(),GCMIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
Edit : I have registered GCM_Receiver statically in this way :
<receiver
android:name="com.myApp.GCM_Receiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.RETRY" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myApp" />
</intent-filter>
</receiver>
Edit : And my GCMIntentService code is below :
public class GCMIntentService extends IntentService{
//Constructor with super().
public GCMIntentService () {
super("GcmIntentService");
}
//Processes gcm messages .
@Override
protected void onHandleIntent(Intent intent) {
Log.d("GCMIntentService ", "GCMIntentService Started");
Toast.makeText(getApplicationContext(), "GCMIntentService Started", Toast.LENGTH_LONG).show();
GCM_Receiver.completeWakefulIntent(intent);
}}