I know neither HashMap nor SparseArray are threadsafe. Do I have to worry about that if I have a central data repository as HashMap which can be accessed by the activity and potentially by an AsyncTask?
Would it be advisable to use a HashTable or better ConcurrentHashMap to be on the safe side?
Yes, you'll have to worry about thread safety. You can either use a HashTable, ConcurrentHashMap, or a synchronization block whenever you're doing IO around the HashMap or SparseArray. The synchronization block acts a bit different and might be slower, but for a simple application, this likely will not be an issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With