N
N
nabokovsafran2015-01-07 18:19:58
Android
nabokovsafran, 2015-01-07 18:19:58

Android. How to get rid of double firing onPageFinished?

Hello. My problem is that in the following code, the onPageFinished function is called twice, which consequently causes startActivity(showMainPage) to run twice.

public class Authorization extends Activity {

    WebView mWebView;
    final String redirect_url = "https://oauth.vk.com/blank.html#access_token=";
    Intent showMainPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authorization);
        mWebView = (WebView) findViewById(R.id.webView);
        showMainPage = new Intent(this, MainActivity.class);
        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.loadUrl(this.getIntent().getStringExtra("url"));
    }

    protected class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            super.shouldOverrideUrlLoading(view, url);
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (url.startsWith(redirect_url)) {
                showMainPage.putExtra("url with token", url);
                startActivity(showMainPage);
                finish();
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yanchumak, 2015-01-07
@yanchumak

just search stackoverflow.com/questions/18282892/android-webvi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question