Closed abdurahmanadilovic closed 2 years ago
We do use FlowSettings, which adds listeners for getXFlow method calls which we do use in our codebase, so I guess that is why addListener is invoked.
The current way to cause a crash like this is to use getXFlow to observe some changes with the FlowSettings class, then perform a delete on the underlying SharedPreferences store, which will then cause a crash like this. We are removing user data upon logout, but I guess we have some listeners active, so we have to make sure that we have no active listeners before SharedPreferences gets deleted right?
Huh, I guess I missed this change in Android 11. I'm not sure how it hasn't already come up before as this looks like it will crash anytime an app sets a listener and then later calls clear()
. Should be a pretty easy fix, though. In the meantime, yes the workaround would be to remove listeners before calling clear.
Oh scratch that, it should be rare because AndroidSettings.clear()
doesn't call clear()
on the SharedPreferences
, it calls remove()
on every key instead. The only time you'll see this issue is if you call preferences.edit().clear().apply()
after setting listeners on AndroidSettings
. So a better workaround is to call clear()
on the Settings
instead of the SharedPreferences
.
This is fixed in version 0.9
Thank you for a swift response and sorry for the late reply. Keep up the good work 👍
Hi, first of all, thanks for this awesome library, we are using in our KMM project, and its working great. We do have this issue that occurs on some devices, we have seen it on android 11 and 12, and not on android 10 and 9. Here is the stack trace
What's strange is that we do not attach any listeners when we are creating the Settings class in our Koin setup. So I am puzzled about how and why is Android SharedPreferences calling notifyListeners.