Android 如何处理未捕获的异常?
我真的无法调试这个问题。我正在开发的应用程序只是崩溃了,甚至当坏代码被封装到一个通用的try-catch中时也是如此 这是“stacktrace”: 如您所见,问题是由于不推荐使用的方法Android 如何处理未捕获的异常?,android,android-webview,stack-trace,Android,Android Webview,Stack Trace,我真的无法调试这个问题。我正在开发的应用程序只是崩溃了,甚至当坏代码被封装到一个通用的try-catch中时也是如此 这是“stacktrace”: 如您所见,问题是由于不推荐使用的方法removeAllCookies。尽管如此,针对姜饼之前的所有设备,我需要这种方法。我的代码是: try { android.webkit.CookieManager webViewCookieManager = android.webkit.CookieManager.getInstance();
removeAllCookies
。尽管如此,针对姜饼之前的所有设备,我需要这种方法。我的代码是:
try {
android.webkit.CookieManager webViewCookieManager = android.webkit.CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webViewCookieManager.removeAllCookies(null);
webViewCookieManager.removeSessionCookies(null);
} else {
webViewCookieManager.removeAllCookie(); // When it tries to execute this line, it crashes.
webViewCookieManager.removeSessionCookie();
}
} catch (Exception e) {
e.printStackTrace();
}
这个异常不可能由try-catch处理!应用程序崩溃了。我不明白为什么,或者如何处理它。我只是缺少
CookieSyncManager
由于removeAllCookies
在不同的线程上操作,因此从未引发异常
要解决:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webViewCookieManager.flush();
webViewCookieManager.removeAllCookies(null);
webViewCookieManager.removeSessionCookies(null);
} else {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this);
cookieSyncMngr.startSync();
webViewCookieManager.removeAllCookie();
webViewCookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webViewCookieManager.flush();
webViewCookieManager.removeAllCookies(null);
webViewCookieManager.removeSessionCookies(null);
} else {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this);
cookieSyncMngr.startSync();
webViewCookieManager.removeAllCookie();
webViewCookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
}