Created
December 20, 2013 08:59
-
-
Save robUx4/8052193 to your computer and use it in GitHub Desktop.
Avoid Webview's to crash when the activity is gone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mv.setWebChromeClient(new WebChromeClient() { | |
@Override | |
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { | |
if (getActivity()==null || !view.getWindowToken().isBinderAlive()) { | |
TouiteurLog.d(false, "pretend we will create a window but it's not possible anymore"); | |
return true; | |
} | |
return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg); | |
} | |
@Override | |
public boolean onJsAlert(WebView view, String url, String message, JsResult result) { | |
if (getActivity()==null || !view.getWindowToken().isBinderAlive()) { | |
TouiteurLog.d(false, "pretend we will create a JsAlert but it's not possible anymore msg:"+message); | |
return true; | |
} | |
return super.onJsAlert(view, url, message, result); | |
} | |
@Override | |
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { | |
if (getActivity()==null || !view.getWindowToken().isBinderAlive()) { | |
TouiteurLog.d(false, "pretend we will create a JsConfirm but it's not possible anymore msg:"+message); | |
return true; | |
} | |
return super.onJsConfirm(view, url, message, result); | |
} | |
@Override | |
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { | |
if (getActivity()==null || !view.getWindowToken().isBinderAlive()) { | |
TouiteurLog.d(false, "pretend we will create a JsPrompt but it's not possible anymore msg:"+message); | |
return true; | |
} | |
return super.onJsPrompt(view, url, message, defaultValue, result); | |
} | |
@Override | |
public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) { | |
if (getActivity()==null || !view.getWindowToken().isBinderAlive()) { | |
TouiteurLog.d(false, "pretend we will run a JsBeforeUnload but it's not possible anymore msg:"+message); | |
return true; | |
} | |
return super.onJsBeforeUnload(view, url, message, result); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment