14

How do I open link in webpage to new activity (what contains WebView aswell)?

I have webpage where is list and every list item contain different link. So I want that when user press first item it opens second activity and load that link to second activity's WebView. Hope you understand what I try to ask :)

Is that possible?

Eljas
  • 1,187
  • 4
  • 17
  • 37

1 Answers1

26

You can override the URL link clicks and open an activity on each click:

    webView = new WebView(this);
    webView.setWebViewClient(new WebViewClient()
        {
            // Override URL
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                Intent intent = new Intent(...);
                startActivity(intent);
                return true;
            }
        });
triad
  • 20,407
  • 13
  • 45
  • 50
  • How do I get that link and pass it to webView.loadUrl(url); (in second activity)? – Eljas Feb 22 '12 at 02:15
  • 2
    You can pass in the URL as an extra with your intent. Then in your second activity, you can extract the extra (URL) and create another webview and load that URL. See here for more info about intents and extras: http://stackoverflow.com/questions/4233873/how-to-get-extra-data-from-intent-in-android – triad Feb 22 '12 at 17:43
  • @triad: I have passed URL and got that in second activity, but webview.loadUrl(newurl), newurl is not displayed... – Ponmalar May 11 '12 at 06:57
  • how can i open a particular activity when a particular link in web view is clicked. for example if the link is https://www.test.com/scan i want a scanner activity to open in the APP. possible ??? –  Oct 11 '20 at 16:47