Question

Here is my code:

public class AuthActivity extends Activity {
public static final String REDIRECT_URL = "redirectUrl";
WebView webview;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    webview = new WebView(this);
    setContentView(webview);

    webview.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            parseUrl(url);
            super.onPageFinished(view, url);
        }
        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            Toast.makeText(getApplicationContext(), description, Toast.LENGTH_LONG).show();
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }
    });
    webview.clearCache(true);
    webview.clearHistory();
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    String url = VKPoster.getAuthUrl( );
    webview.loadUrl(url);
}

private void parseUrl(String url) {
    try {
        if(url==null)
            return;
        if(!url.contains("error=")){
            Intent intent=new Intent();
            intent.putExtra(REDIRECT_URL, url);
            setResult(Activity.RESULT_OK, intent);
        }
        finish();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

When the activity starts loading the page without a webviewclient it stops running, but when the webviewclient is set it works just fine.

Can anyone explain to me this behavior ?

Was it helpful?

Solution

The problem was in this code(when I posted question I have seen it. That's absolutely blowing)

private void parseUrl(String url) {
try {
    if(url==null)
        return;
    if(!url.contains("error=")){
        Intent intent=new Intent();
        intent.putExtra(REDIRECT_URL, url);
        setResult(Activity.RESULT_OK, intent);
    }
    /* I finished app every time page loaded! What a shame */
    finish();
} catch (Exception e) {
    e.printStackTrace();
}

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top