diff options
author | Jan Holesovsky <kendy@collabora.com> | 2020-07-13 18:21:28 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-07-14 14:48:52 +0200 |
commit | 1f0a184edd44c611ea93f71e4ccd5db70ba246ce (patch) | |
tree | 944d8592317fef61a69b7b202268e3ac90958d63 | |
parent | leaflet: removed slide controls from draw (diff) | |
download | online-1f0a184edd44c611ea93f71e4ccd5db70ba246ce.tar.gz online-1f0a184edd44c611ea93f71e4ccd5db70ba246ce.zip |
android: Avoid calling methods of a destroyed WebView.
Avoids exceptions like:
2020-07-13 13:19:49.607 2919-2919/? I/LOActivity: Forwarding to the WebView: 'statusindicatorsetvalue: 86'
2020-07-13 13:19:49.609 2919-2919/? W/cr_AwContents: Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.t(chromium-SystemWebViewGoogle.apk-stable-410410651:2)
at com.android.webview.chromium.WebViewChromium.loadUrl(chromium-SystemWebViewGoogle.apk-stable-410410651:11)
at android.webkit.WebView.loadUrl(WebView.java:970)
at org.libreoffice.androidlib.LOActivity$6.run(LOActivity.java:794)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6971)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:865)
Change-Id: Ic853131bac937deec7e68723b956a4ab7cf61872
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98723
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java index 855fa63b08..5fb44fa979 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java @@ -101,7 +101,7 @@ public class LOActivity extends AppCompatActivity { private URI documentUri; private String urlToLoad; - private WebView mWebView; + private WebView mWebView = null; private SharedPreferences sPrefs; private Handler mMainHandler = null; private RateAppController rateAppController; @@ -544,6 +544,7 @@ public class LOActivity extends AppCompatActivity { if (viewGroup != null) viewGroup.removeView(mWebView); mWebView.destroy(); + mWebView = null; // Most probably the native part has already got a 'BYE' from // finishWithProgress(), but it is actually better to send it twice @@ -780,20 +781,24 @@ public class LOActivity extends AppCompatActivity { */ void callFakeWebsocketOnMessage(final String message) { // call from the UI thread - mWebView.post(new Runnable() { - public void run() { - Log.i(TAG, "Forwarding to the WebView: " + message); + if (mWebView != null) + mWebView.post(new Runnable() { + public void run() { + if (mWebView != null) + Log.i(TAG, "Skipped forwarding to the WebView: " + message); - /* Debug only: in case the message is too long, truncated in the logcat, and you need to see it. - final int size = 80; - for (int start = 0; start < message.length(); start += size) { - Log.i(TAG, "split: " + message.substring(start, Math.min(message.length(), start + size))); - } - */ + Log.i(TAG, "Forwarding to the WebView: " + message); - mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data':" + message + "});"); - } - }); + /* Debug only: in case the message is too long, truncated in the logcat, and you need to see it. + final int size = 80; + for (int start = 0; start < message.length(); start += size) { + Log.i(TAG, "split: " + message.substring(start, Math.min(message.length(), start + size))); + } + */ + + mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data':" + message + "});"); + } + }); // update progress bar when loading if (message.startsWith("'statusindicator") || message.startsWith("'error:")) { |