ConcurrentModificationException in Android while accessing Shared Preferences

前端 未结 2 2347
萌比男神i
萌比男神i 2021-02-20 15:16

When I develop an android app, I run into the exception which I do not have any clue; I have googled related topics but none of them helped.

Fatal Exception: jav         


        
2条回答
  •  广开言路
    2021-02-20 15:55

    Preferences are thread safe(!), but not process safe. The answer of @mohan mishra simply not true, no need to synchronize everything. The problem here, as statet out in another question is, that per documentation you MUST NOT modify any instance that is returned by getStringSet and getAll

    getStringSet()

    Note that you must not modify the set instance returned by this call. The consistency of the stored data is not guaranteed if you do, nor is your ability to modify the instance at all.

    getAll()
    

    Note that you must not modify the collection returned by this method, or alter any of its contents. The consistency of your stored data is not guaranteed if you do.

    To the other question

    Documentation

提交回复
热议问题