pranavsethi96 pranavsethi96 - 2 years ago 163
Android Question

How to start an activity when a link is clicked in webview?

I am developing an android app, which has a webview in it..

I wanted to know how can I load up a specific activity (Eg. - abcd.Java) when a link in the web page is clicked...

I am comfortable in coding either in Web Document or through java and even both.

Thanks in advance :)

Answer Source

just using shouldOverrideUrlLoading:

private class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.equals("YOURLINK")) {
            Intent intent = new Intent(getContext(), YourActivity.class);
            return true; // Handle By application itself
            return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download