【发布时间】:2014-08-02 08:00:06
【问题描述】:
我的应用程序生成多个单独的通知,例如,Notification A, Notification B, Notification C. 等...
如果我点击Notification A,A 的详细信息将可见,之后如果我打开Notification C or B, the activity still shows Notification A contents only。如何使其更新以显示相应的通知数据。我正在为每个通知分配唯一的密钥。
这是我生成通知的代码
CharSequence title = title1;
CharSequence description = notes;
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intent = new Intent(this.getApplicationContext(), Google_task_notification_preview.class);
intent.putExtra("CODE", key);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
this.getApplicationContext(), key, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
try
{
Drawable d = getResources().getDrawable(ic_launcher);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setLargeIcon(bitmap)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(pendingNotificationIntent)
.setSound(soundUri);
if(priority == 0)
mBuilder.setSmallIcon(R.drawable.ic_low);
else
mBuilder.setSmallIcon(R.drawable.ic_high);
mBuilder.setWhen(timestamp);
Notification notification = mBuilder.build();
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;
// cancel notification after click
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// show scrolling text on status bar when notification arrives
notification.tickerText = title + "\n" + description;
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(key, notification);
}
catch(SecurityException se)
{
se.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
【问题讨论】:
-
嗨,在第二个活动中,我正在像
int defvalue = 0; mPrimaryKey = getIntent().getIntExtra("CODE", defvalue); Log.i("mPrimaryKey", String.valueOf(mPrimaryKey));那样做,以获取密钥。但在这里我总是老钥匙 -
嗨,如果我在通知活动中保留断点,第一次只有它命中,其余时间它不会:(。
-
生成 3 到 4 个通知,杀死当前正在运行的实例,然后你尝试一个接一个地打开,在这种情况下它不会工作:(
-
launchMode 的意思是,我没听懂你...你是否通过按主页按钮终止正在运行的活动,然后单独打开通知,你会看到问题
-
哦,很好!对不起,我没有看到你最后的评论。很高兴你成功了!
标签: android android-intent notifications android-notifications android-alarms