I am developing an application where I need to handle some data during the Application session. I do NOT need the data after application is killed or user manually logs out of the application.
I am using POJOs to save the data. POJOs are like Accounts, Users, Campuses, etc. I get all these data in the form of JSON from REST API calls.
As I am fairly new Android development, I am trying to understand which storage approach is recommended in this scenario. (SQLite, SharedPreferences, ApplicationContext, Bundles, ArrayList, Maps, etc)
Performance is important and searches are performed on this data during the user session.
I would need to construct JSON objects often and post back to API.
Any ideas?
Place data on Application
if you don't need to persist your data and its lifecycle is short you might want to create some subclass of Application to hold it. It is the way of having some in-memory global data in the Android Platform - > How-to?
Place data on in memory SQLite table/database
Or you might want some in-memory SQLite tables if this will help you to query the data. In memory tables are also possible in Android. How-to?
Considerations
First method may give you the best performance. All data is on memory, so it is easy to access. But if the data has a very complex structure and queries are complex, you might wanna use SQLite to make querying data easier data. Performance will depend on how much is complex your data and queries. Performance will still be quite good because things are on memory.
But you must be careful. If you end up using too much memory you are going to make your application more likely to be killed by Android framework. And your data will be lost. (5MB may be okay, 10MB might be too much. You will have to test to see what happens.)
If memory pressure is high then you should offload to disk. Performance will be worse, specially when storage is almost full.In that case access may be pretty slow. The simplest way to store and retrieve data is SharedPreferences. You could write you JSON as a String preference. Again if data is too complex and querying it like a database is handy, you could use SQLite.