【问题标题】:Webview keeps old Url on every callWebview 在每次通话时保留旧网址
【发布时间】: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;

【问题讨论】:

    标签: android webview


    【解决方案1】:

    试试这个标志:

    Intent.FLAG_ACTIVITY_CLEAR_TOP
    

    代替:

    Intent.FLAG_ACTIVITY_NEW_TASK
    

    【讨论】:

    • 尝试在不使用静态包装方法的情况下使用bundle注入url!
    【解决方案2】:

    看看这个指南:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

    您必须在 Activity 中覆盖 onNewIntent() 才能访问包含新 URL 的 PendingIntents Bundle。 getIntent() 将始终返回启动 Activity 的原始 Intent。

    【讨论】:

    • onNewIntent 永远不会被调用。
    • "如果 Activity 在其包中将 launchMode 设置为 "singleTop",或者客户端在调用 startActivity(Intent) 时使用了 FLAG_ACTIVITY_SINGLE_TOP 标志,则会调用此方法。"
    • intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);通知通知 = 新我使用此代码: Notification(R.drawable.appiconmenu, message, System.currentTimeMillis()); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);但是 onNewIntent 仍然没有被调用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2020-10-23
    • 2017-09-21
    • 1970-01-01
    • 2012-03-24
    • 2014-09-12
    • 1970-01-01
    相关资源
    最近更新 更多