Android:如何从通知恢复应用程序?
我正在尝试编程我的通知以恢复我的应用程序,而不是简单地启动我的应用程序的新实例。。。我基本上是在寻找它做同样的事情时,主页按钮长按,应用程序是从那里恢复 以下是我目前正在做的事情:Android:如何从通知恢复应用程序?,android,Android,我正在尝试编程我的通知以恢复我的应用程序,而不是简单地启动我的应用程序的新实例。。。我基本上是在寻找它做同样的事情时,主页按钮长按,应用程序是从那里恢复 以下是我目前正在做的事情: void notifyme(String string){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager)
void notifyme(String string){
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
int icon = R.drawable.notification_icon; // icon from resources
CharSequence tickerText = string + " Program Running..."; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = *********; // expanded message title
CharSequence contentText = string + " Program Running...";//expanded msg text
Intent notificationIntent = new Intent(this, Main.class);
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations
// above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
我猜新的意图线就是问题所在。。。任何帮助都将不胜感激 您需要设置您的标志
notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
此外,如果您永远不希望有重复的活动,请在清单中为其指定此属性
android:launchMode="singleTask"
所选答案对我不起作用,但如果其他人查看此答案,则此选项对我起作用:此选项仅在通过“主页”按钮退出应用程序时有效。。。但当应用程序通过“后退”按钮退出时不工作。。。您知道如何解决此问题吗???在notificationIntent中设置操作以指示您正在恢复,在oncreate检查该操作并相应地进行操作时,将需要正确恢复的任何数据以捆绑方式传递到intentReg中@FrankBozzo的评论:默认行为是关闭/销毁“后退”按钮上的“活动”(这至少是
adb logcat
告诉我的)-因此您不能恢复到已终止的活动。。。但是,我相信您可以覆盖默认的后退按钮行为(请参阅WebChromeClient
events)以不退出应用程序。可能重复:,这有助于我回答您的问题吗?