Basically I have an app that would require things(around 20 index files) to be loaded at the start of the app in-order to do some instant-searching later in the app. Although all in all, the index files totally is only several hundred K, as decompression has to be done, the loading actually takes a while. So I am wondering if it is possible to keep it in memory by running service? I wrote a local service within the same package with my app. And when I force closed my app, my service closes too. Should I be using a remote service? if so what I have to do is when I open up my app, it should be able to get 1 int[] and 1 ArrayList from the service, is this doable? or are there any other better options? Thanks a lot
Share
Keep in mind – you’re developing for a mobile phone. Memory is limited. Your app will not be the only app the user will be running. Trying to hog memory persistently for the benefit of your own app is bad practice. The user will not want to have your service running all the time.
Sure, the operating system will eventually kick your service out of the window if memory gets tight, but it’s better practice to not use a service to store data. Use a separate thread on startup and decompress the data.
You could consider writing the decompressed index file to external storage, or compressing it in chunks so that you can get by without having to decompress the entire thing.
If you really think this is an important feature for your app, make it optional in the settings and add a service (possibly even using a broadcast receiver on boot if your app is so important to the user) to load and decompress the data. But I would really recommend against having a service for storage, if that’s what you’re planning to use.