3
我花了一個星期找到解決方案,但沒有成功,所以我需要幫助。Android:通知開始新的活動,而不是恢復舊的活動,如果最初的活動不是從啓動器啓動
當我的應用程序轉到後臺時,會出現通知並顯示活動狀態。
如果應用程序是從啓動器啓動的(使用action = android.intent.action.MAIN
和category = android.intent.category.LAUNCHER
),它可以很好地工作。 但如果應用程序啓動f.e.從畫廊使用動作android.intent.action.SEND
或android.intent.action.SEND_MULTIPLE
和類別android.intent.category.DEFAULT
,則通知開始新的活動,而不是恢復現有活動。
通知代碼:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
Notification notification = new Notification(icon, null, 0);
notification.flags |= Notification.FLAG_ONGOING_EVENT|Notification.FLAG_AUTO_CANCEL|Notification.FLAG_ONLY_ALERT_ONCE;
Context context = this.getApplicationContext();
CharSequence contentTitle = "XXX";
CharSequence contentText = "XXX";
Intent notificationIntent = new Intent(context, MyClass.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent activityIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, activityIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
換句話說,我有一個應用程序「我的應用」活動與「我的活動」。如果在圖庫頂部開始「我的活動」並創建通知,那麼在按下通知「我的應用程序」開始後,而不是通過「我的活動」恢復圖庫。
你有什麼想法如何治癒嗎?