1

Using Webview am loading web url in android.Basically in webview am loading Login Page web url .That page allow user to login with using openid like Facebook and Google.

My scenario is after user logged-in i need to start another activity.So far In web view i loaded Login Page web url.But now I need to call another activity after webview loaded.So please help me anyone how can i achieve this? Thanks in advance.

user3824494
  • 101
  • 2
  • 9

3 Answers3

2

Override onPageFinished() and also check if you are on correct page (after logging in), otherwise your activity will be opened also when login page will be loaded.

webView.setWebViewClient(new WebViewClient(){
    @Override
    public void onPageFinished(WebView view, String url) {
        if(url.equals("url after sucessfull login")){
            Intent intent = new Intent(getApplicationContext(), YourActivity.class);
            startActivity(intent);
        }
    }
});
Dario
  • 2,053
  • 21
  • 31
1

Override the onPageFinished of WebViewClient

 private class WebActivity extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
 }


  @Override
  public void onPageFinished(WebView view, String url) {
   super.onPageFinished(view, url);
    //Call another activity
    }
 }
Jambaaz
  • 2,788
  • 1
  • 19
  • 30
0

I'm not sure the exact experience you are going for, but one possibility is that you have a link on the page that maps to one of your app's intent filters - clicking this link (or redirecting the user to it) would launch your intent. You should probably use a custom scheme for such a link.

Android Respond To URL in Intent shows an example of how to do this. You'll probably have to work out some details of what happens to the UI when this link is clicked - at the least you need to give the user some feedback. Or for a redirect, you almost certainly will need to draw some UI - chrome has a habit of going to a blank page for redirects that launch apps, so if you don't render any UI with your intent (and launch it via a redirect or window.location) your users will probably end up staring at a blank screen.

Community
  • 1
  • 1
David Goldstein
  • 370
  • 3
  • 12