我有一個帶有項目列表的FragmentActivity,當應用程序在後臺時,可以推送到該項目列表。FLAG_ACTIVITY_REORDER_TO_FRONT ignored
發生這種情況時,我想創建狀態欄通知並提醒用戶更新。
當用戶點擊通知時,活動應重新排序並顯示在屏幕上,同時在列表底部顯示新項目。
所以我寫一個通知管理器顯示該用戶設備上:
private static void createNotification(String title, String text,
String largeIcon, String itemdId, Context mCOntext) {
Bitmap ic = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.ic_launcher);
Intent intent = new Intent(mContext, MyFragmentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(MyFragmentActivity.SELECTED_ITEM_LIST_ID, DatabaseHelper
.getItemListById(listId).getId());
PendingIntent pIntent = PendingIntent.getActivity(mContext, 0, intent,
0);
Notification noti = new NotificationCompat.Builder(mContext)
.setContentTitle(title).setContentText(text)
.setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent)
.setAutoCancel(true).setLargeIcon(ic).build();
noti.defaults |= Notification.DEFAULT_LIGHTS;
noti.defaults |= Notification.DEFAULT_VIBRATE;
noti.sound = Uri.parse("android.resource://"
+ mContext.getPackageName() + "/" + R.raw.user_gets_message);
NotificationManager nm = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
唯一的問題是,它似乎忽略了自己的旗幟,當我瀏覽到片段活動,然後去我主屏幕(背景應用程序),並獲得推動,當我點擊通知時,應用程序創建一個新的活動(或片段),並顯示新的數據而不是原始數據。 (這意味着點擊後退按鈕會從歷史堆棧中打開相同的活動(或片段)
我覆蓋了onNewIntent
以及該活動的所有生命週期方法,並且我看到在返回單擊時,被稱爲是MyFragmentActivity.onStart
和MyFragmentActivity.onResume
。
任何想法上它是什麼,我做錯了嗎?