I am building a simple task list app which stores and retrieves tasks from shared preferences using the Gson library. At this point there isn't any noticeable delays or glitches so I'm wondering is it necessary or may become necessary at some point. For example, if I decide to switch to another local data source like SQLite or Room would it become necessary?
2 Answers
Are background threads necessary if I am storing and retrieving data locally on Android?
It is generally a good idea.
I am building a simple task list app which stores and retrieves tasks from shared preferences using the Gson library.
If you are using apply()
on your SharedPreferences.Editor
to persist your changes, it is doing the work on a background thread for you.
I decide to switch to another local data source like SQLite or Room would it become necessary?
"Necessary" is a strong term. If you plan on distributing the app, it would be a good idea to use background threads. Whether those are threads that you create, or whether those are threads that something else creates (e.g., Room, RxJava), may vary.

- 986,068
- 189
- 2,389
- 2,491
if you mean SQLITE by locally.the answer is YES.
if you are using the raw sqlite queries the compiler will permit you to make queries in UI thread although it is not a good practice and may cause the UI thread to freeze so it will hurt your application performance but if you are using "ROOM" the compiler will throw an error if you try to make database operation from the UI thread. so

- 656
- 4
- 19