Android Notification Bar打开最后的活动活动?
-
28-09-2019 - |
题
我正在创建像计时器应用程序一样,当我启动计时器时,我可以选择去Android Home或开始任何其他活动。
当我启动计时器时,我会设置一个通知栏图标,如果我使用其他应用程序(Mean Mean从“启动计时器”活动中获取),现在我需要通过单击通知图标来回到以前启动的计时器活动???
当我单击时,我正在启动新的实例计时器活动,而不是先前启动的计时器活动! ,如果我单击返回按钮,它会向我显示以前的计时器活动。
问题是:如何致电以前开始启动活动槽通知栏,不要启动该活动的新实例?
这是我下面我的代码的示例:
private void notificationBar()
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ico;
CharSequence tickerText = "some title...";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "some app title";
CharSequence contentText = "...some info !";
Intent notificationIntent = new Intent(this, main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIF_ID, notification);
}
private void notificationClose(int notifID)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.cancel(notifID);
}
解决方案
我找到了一个关于旗帜的答案:Android:new Intent()从Android:lainingMode =“ singletop”开始新实例
Intent intent= new Intent(context, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
其他提示
我不确定我理解你的意思。
我想您可以在意图中添加额外的意图,以指定确切使用的通知来调用您的应用程序。这根本有帮助吗?
不隶属于 StackOverflow