我正在使用C2Dm服务将通知推送到我的应用。我有一个只包含一些公司设计元素和webview的活动。
当我第一次启动我的应用并将网址推送到设备时,用户会在通知栏中收到通知。如果他点击通知,我会创建一个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);
}
我的意图有问题吗?我必须以不同的方式打电话吗?是webview吗?
更新
Intent intent = new Intent(sender, WebviewActivity.class);
extras.putString(DESTINATION_URL, destUrl);
intent.putExtras(extras);
return intent;
答案 0 :(得分:1)
试试这个标志:
Intent.FLAG_ACTIVITY_CLEAR_TOP
而不是:
Intent.FLAG_ACTIVITY_NEW_TASK
答案 1 :(得分:1)
请查看本指南:http://developer.android.com/guide/topics/ui/notifiers/notifications.html
您必须覆盖Activity中的onNewIntent()才能访问包含新URL的PendingIntents Bundle。 getIntent()将始终返回启动Activity的原始Intent。