schlingel
schlingel

Reputation: 8575

Webview keeps old Url on every call

I'm using a C2Dm service to push notifications to my app. I have an activity which consists only of some corporate design elements and the webview.

When I start my app for the first time and push a url to the device the user gets an notification in the notification bar. If he clicks on the notification I create a PendingIntent to start the webview-activity.

Till here, everything is fine. But the App keeps opening the first URL it got via C2DM message and never shows a new url. The url itself is passed via bundle extra.

So here's the code to create the pending intent for the notification:

    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);

On the WebviewActivity site the code looks like that:

    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);
    }

Is there something wrong with my intent? Do I have to call it differently? Is it the webview?

UPDATE:

    Intent intent = new Intent(sender, WebviewActivity.class);      
    extras.putString(DESTINATION_URL, destUrl);
    intent.putExtras(extras);

    return intent;

Upvotes: 2

Views: 712

Answers (2)

SeanPONeil
SeanPONeil

Reputation: 3910

Take a look at this guide: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

You have to override onNewIntent() in your Activity to access the PendingIntents Bundle that contains the new URL. getIntent() will always return the original Intent that started the Activity.

Upvotes: 1

Maher Abuthraa
Maher Abuthraa

Reputation: 17813

try this flag :

Intent.FLAG_ACTIVITY_CLEAR_TOP

instead of:

Intent.FLAG_ACTIVITY_NEW_TASK

Upvotes: 1

Related Questions