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);
换句话说,我有一个应用程序“我的应用”活动与“我的活动”。如果在图库顶部开始“我的活动”并创建通知,那么在按下通知“我的应用程序”开始后,而不是通过“我的活动”恢复图库。
你有什么想法如何治愈吗?