【发布时间】:2016-03-05 18:07:25
【问题描述】:
在我的应用程序中,当点击推送通知时,我无法使用新信息(捆绑数据)重新创建活动。以下是我的推送通知流程的步骤。
第 1 步: 我在单击推送通知时打开 Activity B,其中显示在 Activity B 中的信息。
第 2 步: 点击主页按钮或转到其他一些活动,以便活动 B 进入后台 (OnPause) 状态。
第 3 步:
现在,我再次通过单击带有新信息但 Activity B goes to onResume instead of onCreate state 的推送通知打开活动 B。
我的要求是它应该进入 onCreate 状态,以便我可以处理新信息。 IActivity B 如何进入 onResume 而不是 onCreate 状态?我在通知接收器类中做了以下操作。
Intent intent = new Intent(this, ListScreenActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("res_id", requestCode);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("uid", id_value);
intent.putExtras(bundle);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, requestCode, intent,0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext());
Notification notification = mBuilder
.setSmallIcon(R.mipmap.ic_launcher)
.setTicker(tickerMessage)
.setWhen(0)
.setAutoCancel(true)
.setContentTitle(app_name)
.setStyle(new NotificationCompat.BigTextStyle().bigText(tickerMessage)
.setContentIntent(resultPendingIntent)
.setContentText(tickerContent).build();
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(), notification);
注意:
这里ListScreenActivity (Activity B) is not Launcher activity
【问题讨论】:
标签: android android-intent notifications