3 回答

TA貢獻(xiàn)1906條經(jīng)驗 獲得超3個贊
我遇到類似的問題,我的應(yīng)用程序顯示消息通知。當(dāng)有多個通知并單擊每個通知時,它將在查看消息活動中顯示該通知詳細(xì)信息。我解決了在視圖消息意圖中接收到相同額外參數(shù)的問題。
這是修復(fù)此問題的代碼。用于創(chuàng)建通知意圖的代碼。
Intent notificationIntent = new Intent(getApplicationContext(), viewmessage.class);
notificationIntent.putExtra("NotificationMessage", notificationMessage);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(),notificationIndex,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(getApplicationContext(), notificationTitle, notificationMessage, pendingNotificationIntent);
查看消息活動的代碼。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onNewIntent(getIntent());
}
@Override
public void onNewIntent(Intent intent){
Bundle extras = intent.getExtras();
if(extras != null){
if(extras.containsKey("NotificationMessage"))
{
setContentView(R.layout.viewmain);
// extract the extra-data in the Notification
String msg = extras.getString("NotificationMessage");
txtView = (TextView) findViewById(R.id.txtMessage);
txtView.setText(msg);
}
}
}
- 3 回答
- 0 關(guān)注
- 391 瀏覽
添加回答
舉報