【发布时间】:2012-01-26 00:32:49
【问题描述】:
我正在使用 C2Dm 服务将通知推送到我的应用程序。我有一个活动,它只包含一些企业设计元素和 web 视图。
当我第一次启动我的应用程序并将 URL 推送到设备时,用户会在通知栏中收到通知。如果他点击通知,我会创建一个 PendingIntent 来启动 webview-activity。
到这里为止,一切都很好。但是该应用程序不断打开它通过 C2DM 消息获得的第一个 URL,并且从不显示新的 URL。 url 本身是通过 bundle extra 传递的。
下面是为通知创建待处理意图的代码:
Intent intent = WebviewActivity.asIntent(context, getUrlWithAttachedAccesskey(notification.getUrl()), new Bundle()); // just a static method to wrap the bundle correctly
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification = new Notification(R.drawable.appiconmenu, message, System.currentTimeMillis());
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, title, message, pIntent);
notificationMan.notify(getNextNotificationId(), notification);
在 WebviewActivity 网站上,代码如下所示:
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if(extras != null) {
String url = intent.getExtras().getString(DESTINATION_URL);
Log.i(TAG, "Loading url: " + url);
wbVwBrowser.loadUrl(url);
}
我的意图有问题吗?我必须以不同的方式称呼它吗?是网页视图吗?
更新:
Intent intent = new Intent(sender, WebviewActivity.class);
extras.putString(DESTINATION_URL, destUrl);
intent.putExtras(extras);
return intent;
【问题讨论】: