【发布时间】:2013-09-29 01:06:14
【问题描述】:
在加载 Webview 的主 Activity 中,根据启动它的位置确定要加载的 url。
Bundle extras = getIntent().getExtras();
if (extras != null) {
String theurl = getIntent().getExtras().getString("url");
webView.loadUrl(theurl);
} else {
webView.loadUrl("http://mysite.com");
}
如果应用程序是新实例并从主屏幕加载,它会加载默认 url。
如果应用程序未运行并且我单击通过谷歌云消息发送的通知,应用程序将加载自定义 URL。
按预期运行。
我的问题在于当应用程序已经在后台运行时,当我单击通知时,它会将应用程序带到最前面但不会加载新的 url,它保持默认。
我对标志不太确定,我之前确实遇到过这个问题,是某种标志组合解决了这个问题。
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("url", url);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
int requestID = (int) System.currentTimeMillis();
PendingIntent intent = PendingIntent.getActivity(context, requestID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
我们将不胜感激。
编辑
如果我添加标志 PendingIntent.FLAG_CANCEL_CURRENT 这几乎可以解决问题,虽然它重新加载整个主要活动(启动屏幕被调用),但我希望它重用现有的 webview。
【问题讨论】:
标签: android android-intent android-pendingintent