Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question