Looks like a familiar question. But i could not get a perfect solution, hence this question.
In my application i am fetching a data of 30k strings and storing it in a String Array. Since it takes a lot of time to fetch this data from a web server, i am performing this action in the background and showing a splash screen in the UI thread till then.
So this Array of strings is created and populated in SplashActivity and made Public Static. And i am using this in the next activity named ListViewActivity, just like this:
SplashActivity.myArrayOfStrings;
Here the problem is when i am in ListViewActivity and i press Home button, leave it for 3-5 mins and try to reopen the app, it says ArrayIndexOutOfBoundsException because that Array items in SplashActivity are destroyed and i am trying to access its values in the ListViewActivity.
So i what to know how i can store such data to use it in all the Activities with only 1 time fetching.
I don’t want anything like a Shared Preference because there 30k Strings will change every day.
I never used SQLite in my app, but if i store the Strings in a DataBase while i am in SpalshActivity can i use the data in every other Activity? I mean will this data be there even when my app goes to background and reopened 5 mins later??
Or is there any better and obvious solution??
Thank You
Storing so many datas must be done in a SQLite DB. You should not rely on any data store in an activity class to be permanent, because the activities will be recycled at will by the system (and then have a higher probability to, if the memory is low…)
On the contrary, the data stored in SQLite are supposed to be permanent, even if you close your activity, your app, or even if you shut-off your phone.