忽略了FLAG_ACTIVITY_REORDER_TO_FRONT

the*_*osh 4 android android-intent android-pendingintent

我有一个带有项目列表的FragmentActivity,当应用程序在后台时,可以推送到该项目列表.

发生这种情况时,我想创建状态栏通知并提醒用户更新.
当用户单击通知时,活动应重新排序到前面并在屏幕上显示,同时在列表底部显示新项目.

所以我写了一个通知管理器,在用户设备上显示:

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);
}
Run Code Online (Sandbox Code Playgroud)

唯一的问题是它似乎忽略了我的旗帜,当我导航到片段活动,然后转到我的主屏幕(应用程序的背景),并获得推送,当我点击通知时,应用程序创建一个新的活动(或片段)并显示新的一个而不是原始的新数据.(这意味着单击后退按钮可从历史堆栈中打开相同的活动(或片段).

我重写了活动的onNewIntent所有生命周期方法,我看到在后面点击时,被调用的方法是MyFragmentActivity.onStartMyFragmentActivity.onResume.

关于我做错了什么的任何想法?

che*_*tov 6

我认为这个问题是您设置的活动发射模式为singleTask该标志添加FLAG_ACTIVITY_BROUGHT_TO_FRONT到你的意图,并导致标志FLAG_ACTIVITY_REORDER_TO_FRONT被忽略.

您需要将启动模式更改为单顶.