android - Bundle 数据未在从服务中的通知传递的 Activity 中更新,始终填充第一个 bundle

标签 android android-notifications

我正在使用 GCMIntentService 在我的应用程序中处理推送通知。我正在创建一个状态栏通知并使用挂起的 Intent 导航到一个 Activity 。

我创建通知的代码是:

private static void generateNotification(Context context, String message, String  title1, String desc, String soln, String date, String time) {
 int icon = R.drawable.notification_icon;
    long when = System.currentTimeMillis();
        Log.i("","@@##@@ notificatin"+title1+desc+soln+message);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context,AppLog.class);
    notificationIntent.putExtra(Description.REQUEST_FROM, "notification");
    notificationIntent.putExtra(Description.INFO_TITLE, title1);
    notificationIntent.putExtra(Description.INFO_DESC, desc);
    notificationIntent.putExtra(Description.INFO_SOLUTION, soln);
    notificationIntent.putExtra(Description.INFO_DATE, date);
    notificationIntent.putExtra(Description.INFO_TIME, time);
    PendingIntent pIntent = PendingIntent.getActivity(context,  0,notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, pIntent);
    Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notification.sound=uri;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

在我的 AppLog.class 中,我的处理方式如下:

 if(bundle!=null && bundle.containsKey(Description.REQUEST_FROM)){

        Log.i("","@@##@@ applog"+bundle);

    }

当第一个通知发送到设备时,数据将正确填充到我的 AppLog Activity 类中。但是对于所有通知,它总是向我显示旧包。

我尝试了所有方法,但问题仍然存在。从服务创建的待定 Intent 或通知是否有任何问题?

最佳答案

这行得通

PendingIntent pIntent = PendingIntent.getActivity(context,  0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

关于android - Bundle 数据未在从服务中的通知传递的 Activity 中更新,始终填充第一个 bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19300002/

相关文章:

android - 如何打开有通知到通知栏的应用?

android - 适用于 Android 的 Visual Studio 模拟器是否支持 OpenGL ES 3.0?

android - 为什么 FLAG_KEEP_SCREEN_ON 不能正常工作?

android - 单击通知没有开始预期的 Activity ?

Android - 如何容纳在 AsyncTask doInBackground 方法中执行的线程

android - 我可以使用作业调度程序发送通知吗?

android - 点击 Android 通知后的 AlertDialog

android - 扩展 Android.util.Log 以写入文件

Android : Using Min3d library to load Wavefront . obj 文件,第二次启动因 OutOfMemoryError 而崩溃

android - Android 4.1 上的 AlertDialog 问题