-2

my main activity contains a webview, and i have a notification which says the program is running and when the user clicks on the notification the main activity opens. and my problem is when the user clicks on the notification my main activity starts from oncreate method and the url opens again BUT i DON'T want to reopen the URL.

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74
john
  • 9
  • 6

1 Answers1

0

First move the code that load the URL from onCreate to onResume

If url is the page you want to open

public void onResume(...) {
    // ...

    String url = "...";
    if (!url.equals(webView.getUrl())) {
        webView.loadUrl(url);
    }
}

Note that if your app has been in the background for a while, Android will kill it, and the webview will reload - nothing you can do about it.

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74