-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use SaveInstanceState
to avoid crash in export file when Activity is recreated
#14797
use SaveInstanceState
to avoid crash in export file when Activity is recreated
#14797
Conversation
I came across this when I was reproducing #14795, and regarding this issue we can use shared prefs to overcome it what say? |
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
@lukstbit any updates on the issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented the changes I wanted but it didn't touched the mExportFileName part of the code. So this PR is needed, I left some review notes on this.
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
@@ -277,7 +284,7 @@ class ActivityExportingDelegate(private val activity: AnkiActivity, private val | |||
* This will allow to check whether a recent export was made, hence scoped storage migration is safe. | |||
*/ | |||
private fun saveSuccessfulCollectionExportIfRelevant() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method should be changed to receive the path as a parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was not handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called from two other methods, in one the path is available and could be passed directly and in the other method, saveFileCallback you could retrieve the filename from preferences and pass it to saveSuccessfillColl... and also to exportToProvider() which would allow us to avoid exportfilename?:"".
Minor: we should remove the name from ACRA reports in the method: |
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
@@ -277,7 +279,7 @@ class ActivityExportingDelegate(private val activity: AnkiActivity, private val | |||
* This will allow to check whether a recent export was made, hence scoped storage migration is safe. | |||
*/ | |||
private fun saveSuccessfulCollectionExportIfRelevant() { | |||
if (::mExportFileName.isInitialized && !mExportFileName.endsWith(".colpkg")) return | |||
if (!mExportFileName!!.endsWith(".colpkg")) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are in a new method here, and the activity may be recreated, but I don't see the filename fetched from prefs and initialized again?
If lukstbit had been handled instead of just resolved and closed without handling, then it would be a method parameter (non-null...) and you wouldn't need the dangerous !! on a var that I think is not initialized at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still a risk of it being null (it is 99.9% sure though it won't be null) as getString(EXPORT_FILE_NAME_KEY, "")
automatically assigns null value to the pref in case it is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it automatically assigned ""
to the pref in case it is null.
This doesn't seem to actually address the substance of my comment tho?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am pushing the changes for that part I have used elvis operator though in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't escape the evil "!!" here if (!mExportFileName!!.endsWith(".colpkg")) return
Is it feasible to use |
I guess that creates the need for extra calls from the activity where we are using this class, we can avoid that by using the prefs here itself |
Using saved state now instead shared pref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one issue regarding invalid states, rest looks great, thanks!
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
At some point @criticalAY you're going to need to learn how to use git rebase and clean up your commits - this should be a one commit PR, I have no idea why there are 9 different commits most with same title |
Give me a moment, will do it |
@@ -83,7 +83,7 @@ object CrashReportService { | |||
private fun createAcraCoreConfigBuilder(): CoreConfigurationBuilder { | |||
val builder = CoreConfigurationBuilder() | |||
.withBuildConfigClass(com.ichi2.anki.BuildConfig::class.java) // AnkiDroid BuildConfig - Acrarium#319 | |||
.withExcludeMatchingSharedPreferencesKeys("username", "hkey") | |||
.withExcludeMatchingSharedPreferencesKeys("username", "hkey", "file_prefs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a thing? Seems related to the previous design that was saved preferences based, but now you're using the bundle passed between previous-killed-activity and newly-resumed-activity ?
85cb5a7
to
18f1618
Compare
18f1618
to
393f61b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks clean + correct to me know and also "lighter" using the saved instance state style. It's changed a lot and with the rebase + push I'm going to ask for one more approval but I think it's smooth sailing. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, another round due to the use of ""
as a path
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
SaveInstanceState
to avoid crash in export file when Activity is recreated
AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt
Outdated
Show resolved
Hide resolved
squash-merge
|
there was a linting error causing the code quality failure so the latest commit fixes that nothing else |
d3d3286
to
352afe5
Compare
…s recreated (ankidroid#14797) * use saved instance state to avoid the crash if activity is destroyed * fixing test issues
Hi there @criticalAY! This is the OpenCollective Notice for PRs merged from 2023-12-01 through 2023-12-31 If you are interested in compensation for this work, the process with details is here: https://github.com/ankidroid/Anki-Android/wiki/OpenCollective-Payment-Process#how-to-get-paid We only post one comment per person per month to avoid spamming you, regardless of the number of PRs merged, but this note applies to all PRs merged for this month Please understand that our monthly budget is never guaranteed to cover all claims - the cap on payments-per-person may be lower, but we try to make our process as fair and transparent as possible, we just need your understanding. Thanks! |
Purpose / Description
Remove the lateinit var and use shared pref and nullable string to avoid crash in case the developer's option is turned on
Fixes
Fixes #14795
How Has This Been Tested?
google emulator
Screen_recording_20231124_152918.webm
Links to blog posts, patterns, libraries or addons used to solve this problem
Checklist
Please, go through these checks before submitting the PR.