嗨,我已经能够显示我的活动的通知,当用户点击通知时,应用程序重新启动.但是我只是希望它重新出现而不是重启.例如.它是一个Web应用程序,我希望它在用户选择通知时出现在前面..但不刷新网页.我可以捕获这个意图还是我发错了意图?通常,如果我按下主页按钮并单击应用程序图标,应用程序就会出现并且不会刷新/重新启动.所以这就是我想要的行为.有任何想法吗 ?
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); …Run Code Online (Sandbox Code Playgroud) notifications android background foreground android-pendingintent
我有一个Android应用程序,当它运行服务时,我想在状态栏上显示通知.然后用户可以通过按HOME键导航到其他应用程序.但是,当我尝试通过通知图标将之前运行的应用程序恢复到Front时,现有活动存在一些问题.即使我将其声明为"单顶"模式(我想运行现有的活动,因为有关联的服务正在运行),不知何故,在OnResume之前已经调用了活动的OnDestroy.这是我创建通知对象的代码.你能指点我错了吗?谢谢.
private void showNotification ()
{
Intent toLaunch = new Intent(getApplicationContext(),
MySingleTopActivity.class);
PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0,toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(getApplicationContext(),
getText(R.string.GPS_service_name), text, intentBack);
....
}
Run Code Online (Sandbox Code Playgroud)