Android 状态栏通知未更新

Android 状态栏通知未更新,android,notifications,Android,Notifications,我正在应用程序中发送状态栏通知。始终显示第一个通知,当我发送第二个后续通知时,它不会得到更新,并且始终显示第一个通知。我是Android的新手,请帮我解决这个问题 我的代码如下 //create notification manager NotificationManager mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOT

我正在应用程序中发送状态栏通知。始终显示第一个通知,当我发送第二个后续通知时,它不会得到更新,并且始终显示第一个通知。我是Android的新手,请帮我解决这个问题

我的代码如下

//create notification manager
NotificationManager mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
//create notifcation
Notification notification = new Notification(R.drawable.ic_launcher,"My App", System.currentTimeMillis());
Intent intent1 = new Intent(this.getApplicationContext(),SaveTask.class);
 notification.flags |= Notification.FLAG_AUTO_CANCEL;

PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);

notification.setLatestEventInfo(this.getApplicationContext(), "New Msg","First message", pendingNotificationIntent);

mManager.notify(0, notification);

首先,您应该开始使用Notification.Builder,而不是直接创建Notification类的新实例

以下是使用NotificationBuilder时的外观:

//create notification manager
        NotificationManager mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
        Intent intent1 = new Intent(this.getApplicationContext(),MyActivity.class);

        PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setTicker("My App")
                .setContentIntent(pendingNotificationIntent)
                .setContentTitle("New Msg")
                .setContentText("First message")
                .build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        mManager.notify(98038, notification);