Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中无休止地从GCM意向服务获取通知_Android_Push Notification_Notifications_Broadcastreceiver - Fatal编程技术网

在android中无休止地从GCM意向服务获取通知

在android中无休止地从GCM意向服务获取通知,android,push-notification,notifications,broadcastreceiver,Android,Push Notification,Notifications,Broadcastreceiver,我创建了一个活动,它在通知发生时得到刷新,但我面临的一个问题是,当通知发出时,它会继续发送无休止的相同通知。早些时候,它工作得很好,但我做了一些改变,这已经做到了。请帮帮我。我正在附上我的代码 GCM IntentService类的代码 发送通知代码 这结束了intent类的代码 现在我的活动代码 好的。因此,您的代码所发生的情况是,您正在向接收器发送广播,同时强制再次调用onHandleIntent,结果调用updateActivity方法,该方法再次广播,循环将无休止地继续 在您的updat

我创建了一个活动,它在通知发生时得到刷新,但我面临的一个问题是,当通知发出时,它会继续发送无休止的相同通知。早些时候,它工作得很好,但我做了一些改变,这已经做到了。请帮帮我。我正在附上我的代码

GCM IntentService类的代码

发送通知代码

这结束了intent类的代码

现在我的活动代码


好的。因此,您的代码所发生的情况是,您正在向接收器发送广播,同时强制再次调用
onHandleIntent
,结果调用updateActivity方法,该方法再次广播,循环将无休止地继续

在您的
updateMyActivity
方法中,请更改以下内容:

Intent intent = new Intent("com.google.android.c2dm.intent.RECEIVE");

罪魁祸首是

com.google.android.c2dm.intent.RECEIVE
它在广播时调用OnHandleContent

另外,在活动的
onResume
方法中,请将标记更改为
myMessage

getActivity().registerReceiver(mMessageReceiver, new IntentFilter("myMessage"))

现在GCM已贬值,您可以使用FCM进行通知。@谷歌否我需要使用GCM,因为它处于结束级别。
notify\u No
的值是多少?在sendNotification方法中找不到它。如果(notify_no<9){notify_no=notify_no+1;}否则{notify_no=0;} @NileshSingh@MukeshMishra初始值是多少?这仅适用于通知发出后的第一次通知,但该活动的广播仅适用于第一次
         @Override
public void onResume() {
    super.onResume();
   // connectToDatabase();
    getActivity().registerReceiver(mMessageReceiver, new IntentFilter("com.google.android.c2dm.intent.RECEIVE"));
}

//Must unregister onPause()
@Override
public void onPause() {
    super.onPause();
    getActivity().unregisterReceiver(mMessageReceiver);
}


//This is the handler that will manager to process the broadcast intent
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        // Extract data included in the Intent
        String message = intent.getStringExtra("message");

        //do other stuff here

        connectToDatabase();


    }
};
Intent intent = new Intent("com.google.android.c2dm.intent.RECEIVE");
Intent intent = new Intent("myMessage");
com.google.android.c2dm.intent.RECEIVE
getActivity().registerReceiver(mMessageReceiver, new IntentFilter("myMessage"))