android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 31 +++++----- 1 file changed, 18 insertions(+), 13 deletions(-)
New commits: commit 1a92479087f8050e2654288f6b06bf688141bacb Author: Jan Holesovsky <ke...@collabora.com> AuthorDate: Mon Jul 13 18:21:28 2020 +0200 Commit: Jan Holesovsky <ke...@collabora.com> CommitDate: Wed Jul 15 23:38:13 2020 +0200 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.me...@collabora.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98755 Tested-by: Jan Holesovsky <ke...@collabora.com> Reviewed-by: Jan Holesovsky <ke...@collabora.com> 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 8465ff5e1..430d3265e 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; @@ -532,6 +532,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 @@ -762,20 +763,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:")) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits