0

这是我的代码:

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();
    }
}
}

当活动开始加载没有 webviewclient 的页面时,它会停止运行,但是当设置 webviewclient 时它工作得很好。

谁能向我解释这种行为?

4

1 回答 1

0

问题出在这段代码中(当我发布问题时,我已经看到了。这绝对令人震惊)

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();
}

}

于 2012-11-19T20:28:56.277 回答