I'm getting this annoying error in production that leads to crash my app.
I do PreferenceManager.getDefaultSharedPreferences(context).edit().putLong("key", value).apply();
to save many of my user based preferences
I'm using implementation 'androidx.preference:preference:1.0.0'
but still im getting many
Fatal Exception: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry + 851(HashMap.java:851)
at java.util.HashMap$KeyIterator.next + 885(HashMap.java:885)
at com.android.internal.util.XmlUtils.writeSetXml + 355(XmlUtils.java:355)
at com.android.internal.util.XmlUtils.writeValueXml + 693(XmlUtils.java:693)
at com.android.internal.util.XmlUtils.writeMapXml + 300(XmlUtils.java:300)
at com.android.internal.util.XmlUtils.writeMapXml + 269(XmlUtils.java:269)
at com.android.internal.util.XmlUtils.writeMapXml + 235(XmlUtils.java:235)
at com.android.internal.util.XmlUtils.writeMapXml + 192(XmlUtils.java:192)
at android.app.SharedPreferencesImpl.writeToFile + 639(SharedPreferencesImpl.java:639)
at android.app.SharedPreferencesImpl.-wrap2(SharedPreferencesImpl.java)
at android.app.SharedPreferencesImpl$2.run + 535(SharedPreferencesImpl.java:535)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1133(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 607(ThreadPoolExecutor.java:607)
at java.lang.Thread.run + 761(Thread.java:761)
I do know that many of my preference change occur in background threads, but the android api should be synchronized right?
I've no idea which changes are leading to the crash because as it runs in a separeted thread in android api i cant get more info about the crash
does anyone know what can be this? how to solve it without turn all apply
into commit
? how to get more info?