diff options
author | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2019-11-08 16:41:42 +0100 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2019-11-19 11:55:24 +0100 |
commit | 7de3b4bc881671692d15cfc93a4c887ed77b6c64 (patch) | |
tree | 48a620ef7720face07c8ba219c4c5206a7089950 /android | |
parent | 7f8c9ddbbd26594bb9249cc6295d0170e4bb58e7 (diff) |
android: avoid NPE when trying to create cache file
when the user wildly switches documents in fast succession, mDocument
can be null - not creating a cache file definitely is better than a hard
crash....
Also onSaveInstanceState is meant for lightweight operations (e.g.
storing what file was openend and what position it was scrolled to), not
for backend-storing of data, so move creation of cache file to onStop
instead.
Change-Id: I2452ef24e309ea4a9594eb723e893798b9b47d98
Reviewed-on: https://gerrit.libreoffice.org/82774
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'android')
-rw-r--r-- | android/source/src/java/org/libreoffice/LOKitTileProvider.java | 4 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index 65de28fe884e..0e2649337322 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -406,8 +406,10 @@ class LOKitTileProvider implements TileProvider { Log.i(LOGTAG, "cacheDocument: " + cacheFile); if(isDocumentCached()){ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save")); - }else{ + }else if(mDocument != null){ mDocument.saveAs("file://"+cacheFile, FileUtilities.getExtension(input.getPath()).substring(1),""); + }else{ + Log.w(LOGTAG, "mDocument was null when trying to save cacheDocument: " + cacheFile); } } diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 032a8461a01b..628305d01f13 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -423,6 +423,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin @Override protected void onStop() { Log.i(LOGTAG, "onStop.."); + //save document to cache + mTileProvider.cacheDocument(); hideSoftKeyboardDirect(); LOKitShell.sendCloseEvent(); super.onStop(); @@ -970,8 +972,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - //save document to cache - mTileProvider.cacheDocument(); } } |