Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download large application data pattern

I am developing a map rendering application for Android. The map data is quite big about 1.1 Gb. Since there are limits both in the market and in the phone for .apk size the recommendations is to download it when application starts.

This is the pattern I use now:
1. Main activity (used for rendering the map) checks if the data is avaiable, if not i starts a download activity
2. The download activity starts a local service
3. The service downloads the zip files and unpacks the mapdata
4. The service sends events to the download activity and notifications

I spawn a service since the whole process can take some time from 30min to a couple of hours depending on phone and network.

But I have trouble making sure that only one instance of the program is running, I have tried all combinations of the launchmode property to no help.

As you may understand two instances running will crash the download/unzip.

This is really frustrating! Now I am doing some ugly read/write to sdcard file lock and it is working most of the time to make sure only one instance is running.

I am targeting Android 1.6 and above.

like image 263
Okku Avatar asked Feb 04 '26 02:02

Okku


1 Answers

To avoid problems with multiple instances, you should use remote service instead of local service. This way, you can have only one instance of the service which will download data you need for the application.

like image 86
dstefanox Avatar answered Feb 09 '26 12:02

dstefanox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!