Android的通知重新启动应用程序,但想要恢复 [英] Android Notification restarts app but want to resume
问题描述
您好我有一个能够得到显示我的活动通知,并在用户 点击通知应用程序重新启动。不过,我只是希望它重新出现无法重新启动。例如。它是一个Web应用程序,我想它来前,当用户选择了notification..but不刷新网页。我可以捕获该意图还是我发送了错误的意图是什么?通常情况下,如果我preSS主页按钮,然后点击应用程序图标,应用程序就浮出水面,并且不刷新/重新启动。所以,这就是我想要的行为。任何想法?
字符串NS = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager =(NotificationManager)
getSystemService(纳秒);
//2.Instantiate通知
INT图标= R.drawable.notification_icon;
CharSequence的tickerText =我的应用;在状态行//临时味精
时长= System.currentTimeMillis的();
通知通知=新的通知(图标,tickerText时);
notification.flags | = Notification.FLAG_ONGOING_EVENT;
//3.Define通知扩大的消息,意图:
上下文的背景下= getApplicationContext();
CharSequence的contentTitle =通知;
CharSequence的contentText =我的应用程序! //消息给用户
意图notificationIntent =新的意图(这一点,HelloAndroid2.class);
PendingIntent contentIntent = PendingIntent.getActivity(此,0,
notificationIntent,0);
notification.setLatestEventInfo(背景下,contentTitle,contentText,
contentIntent);
//4.Pass通知到NotificationManager:
最终诠释NOTIFICATION_ICON_ID = 1;
mNotificationManager.notify(NOTIFICATION_ICON_ID,通知);
我在清单把这个
安卓launchMode =singleInstance
这解决了这个问题对我来说。此外这个答案我还没有尝试过这暗示其他感兴趣的东西。
Hi I have a been able to get a notification displayed for my activity, and when the user clicks the notification the app restarts. However I just want it to reappear not restart. eg. it is a web app and I want it to come to the front when the user selects the notification..but not refresh the web page. Can I trap this intent or am I sending the wrong intent? Normally if I press the home button and click on the app icon the app comes to the fore and doesn't refresh/restart. So this is the behaviour I want. Any ideas ?
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
//2.Instantiate the Notification
int icon = R.drawable.notification_icon;
CharSequence tickerText = "My App"; // temp msg on status line
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
//3.Define the Notification's expanded message and Intent:
Context context = getApplicationContext();
CharSequence contentTitle = "Notification";
CharSequence contentText = "My app!"; // message to user
Intent notificationIntent = new Intent(this, HelloAndroid2.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
//4.Pass the Notification to the NotificationManager:
final int NOTIFICATION_ICON_ID = 1;
mNotificationManager.notify(NOTIFICATION_ICON_ID, notification);
I put this in manifest
android:launchMode="singleInstance"
This fixed the problem for me. Also this answer which I have not tried which allude to other things of interest.
这篇关于Android的通知重新启动应用程序,但想要恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!