Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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推送通知单击启动时,活动中的意图数据未更新_Android_Android Intent_Push Notification - Fatal编程技术网

从ANDROID推送通知单击启动时,活动中的意图数据未更新

从ANDROID推送通知单击启动时,活动中的意图数据未更新,android,android-intent,push-notification,Android,Android Intent,Push Notification,我正在为我的android应用程序使用Google cloud messaging。GCM部分正在成功运行。现在,当用户点击状态栏中的通知图标时,我想在UI活动中显示该消息 我正在使用以下代码从通知启动我的结果显示活动 Intent notificationIntent = new Intent(context, ResultShowActivity.class); notificationIntent.putExtra("Message",msg); PendingIntent cont

我正在为我的android应用程序使用Google cloud messaging。GCM部分正在成功运行。现在,当用户点击状态栏中的通知图标时,我想在UI活动中显示该消息

我正在使用以下代码从通知启动我的结果显示活动

Intent notificationIntent = new Intent(context, ResultShowActivity.class);
   notificationIntent.putExtra("Message",msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this).setSmallIcon(R.drawable.gcm_cloud)
            .setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
消息正确发送,并在GCM通知出现时正确显示,但当我在ResultsShowActivity中捕获额外的意图时,它始终显示旧消息。 我使用以下代码在ResultShowActivity中接收来自intent的消息

String GCMMsg = showViewIntent.getStringExtra("Message");  
我已尝试使用删除ResultShowActivity中的

intent.removeExtra("Message"); 


任何人都可以建议如何从intent检索更新后的邮件。谢谢您的帮助。

请使用以下代码

int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);


PendingIntent contentIntent = PendingIntent.getActivity(this,iUniqueId,notificationIntent, 0);
而不是遵循一行代码

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

希望这会有所帮助,请使用以下代码

int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);


PendingIntent contentIntent = PendingIntent.getActivity(this,iUniqueId,notificationIntent, 0);
而不是遵循一行代码

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

希望这将有助于

您需要将
意向标志、活动标志、单一标志、顶部标志添加到意向标志,将未决内容标志、更新标志、当前标志添加到未决意向标志

Intent intent = new Intent(this,YourActivity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = 
PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

重要提示:确保实施
onNewIntent(意图)
。当您的活动位于前台时,将调用此函数。您需要将意向。标志\u活动\u单个\u顶部添加到意向标志,将挂起内容。标志\u更新\u当前添加到挂起意向标志

Intent intent = new Intent(this,YourActivity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = 
PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

重要提示:确保实施
onNewIntent(意图)
。当您的活动位于前台时,将调用此函数。非常好的提示。很多;-)很好的提示。很多;-)