1
場景: 我的應用程序有一個包含ViewPager的活動,它顯示兩個片段(稱爲頁面A和頁面B)。在與PendingIntent相同的活動中選擇通知,但不同的ViewPage
問題: 當在後臺事件觸發在網頁A的通知,並且用戶在網頁B,選擇通知不執行任何;即沒有回調的onCreate()的onResume(),onNewIntent(),onResumeFragments(),或在onStart()和用戶停留在頁面B.
問:
- 怎麼回事當用戶 選擇了通知並且在頁面B上時,可能使ViewPager顯示頁面A?
或
- 是否有可能,活動內,當用戶已經選擇 指向相同活性的通知來檢測?
代碼通知:
// Create a notification
final Context ctx = this;
Intent notificationIntent = new Intent(ctx, ActivityMain.class);
notificationIntent.putExtra(INTENT_EXTRA_NOTIFICATION, true);
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = ctx.getResources();
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, REQUESTCODE_ACTIVITYMAIN_LISTFRAGMENT, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(ctx);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)//required
.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
.setContentTitle(res.getString(R.string.notification_title))//required
.setContentText(data.description)//required
.setTicker(res.getString(R.string.notification_title))
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
.setAutoCancel(true);
Notification notification = builder.build();
notificationManager.notify(mNotificationID, notification);
也許有一個標誌/配置可添加到通知的意圖迫使活動認識到所選擇的通知?