1

I have an Android app that start a service when the activity starts. The service downloads a lot of data during the startup routine. The service is configured as START_STICKY, so it restarts automatically. Problem is that during tests, I found out that the service is restarted a lot of times, so it continually downloads the same data over and over.

I'm asking if there is a "best pratices" for this case, or if there is a way to prevent continue restarts.

Thank you.

kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
Marco Fedele
  • 2,090
  • 2
  • 25
  • 45
  • This sounds just like: http://stackoverflow.com/questions/20891698/upload-large-file-in-background-service-restarting-when-the-app-closed/20892009 except most servers accept 'ranged-gets' – Matt Jan 03 '14 at 13:12
  • 1
    Maybe system frees memory and also this service? Have you tried making it foreground? Also adding notification for your service will make it live longer. – marcinj Jan 03 '14 at 13:12
  • Your android os is killing your service due to low memory issues and after resources available restarting your service.. – kalyan pvs Jan 03 '14 at 13:13
  • I had the same problem. System killed the process. – piobab Jan 03 '14 at 13:14

2 Answers2

0

Though you have not given any code from your end, so it's tough to understand where is the problem, but I would like to suggest you that after the service started from the activity recall the service from the service end and call the service once in a day when the internet available. If the internet not available the it will call the service after few minutes.

It's very easy , you can also do one thing that store those inside local database and from this database show your data. Also do one thing please check if new data available or not , if available then it will notify first user, if user want to do update new data then it will be updated.

It will be best way to solve this problem, if you need any code support then please tell me. Note: User AlarmManager and PendingIntent .

Thanks.

Satyaki Mukherjee
  • 2,857
  • 1
  • 22
  • 26
0

You can try to use the flag "stopWithTask=false" in your service. It will try to not stop you service when something happing with your application. I hope help you with this sollution.

thiagolsilva
  • 439
  • 4
  • 11