0

Scope: Hi, I am developing a Service in Android API. I need this Service for running whole time (while device is running), so receiver for BOOT

android.intent.action.BOOT_COMPLETED

was setup and Service is scheduled by AlarmManager every 10 minutes.

Problem: My OS got some updates and after updating, it kill my service, unschedule Service from AlarmManager. And as far as I do not reboot my device, Service is not started/scheduled.

Question: Is there any event for receivers, that OS is restarted but device is not? Or updates are installed, OS is resumed etc.?

EDIT

Hello, thanks for links and advice.
Nowadays, I'm using library Evernote for scheduling background jobs.
see https://github.com/evernote/android-job
I accepted the truth, that long-living Service is antipattern and BOOT broadcast can be tricky. As result, I used Evernote to schedule simple jobs to repeatly "do my needs". It nice works as expected, resumes after device restart & is compatible with "Android alarm planning" management.
Just a great library.

zegee29
  • 934
  • 7
  • 8
  • try this link [http://stackoverflow.com/questions/10428510/how-to-start-launch-application-at-boot-time-android][1] [1]: http://stackoverflow.com/questions/10428510/how-to-start-launch-application-at-boot-time-android – kAnNaN Jan 14 '14 at 20:22

1 Answers1

1

I am developing a Service in Android API. I need this Service for running whole time (while device is running)

That is generally an anti-pattern on Android.

Is there any event for receivers, that OS is restarted but device is not?

Not in the Android SDK, because there is no concept of "OS is restarted but device is not" in standard Android. When the OS updates, the entire device reboots (at least twice) as part of the update process.

Your device manufacturer must have done something that has the behavior your describe. You may wish to contact that manufacturer to see if they have advice regarding your scenario.

Note that these results ("it kill my service, unschedule Service from AlarmManager") will also occur when the user taps "Force Stop" on your app's screen in Settings. Your code will not run again, even after a reboot, until the user launches your app from the home screen, or something else explicitly invokes one of your components.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Accepted as answer. Updates were manufacturer matter, so Android API is not helpfull here. User swears that device was not restarted. – zegee29 Jan 16 '14 at 10:08