2

I'm developing an app that needs to keep running a background service. That's why I start that service on the onCreate method of the Main Activity.

But what I'd like to do is that service be always running, even if I didn't start the app after a device restart. I know there's a permission that I could use that is called "ON BOOT COMPLETED". i could capture that Broadcast, I know.

But I don't want to ask user for that permission.

What should I do? The app Fucking Weather has a Service always running and in its Manifest it doesn't declare the "ON BOOT COMPLETED" permission. How do they do that trick? That's what I need.

I tried an AlarmManager that executes every X seconds, but it won't start until the app is not open.

Joaquin Iurchuk
  • 5,499
  • 2
  • 48
  • 64
  • They may be listening for another broadcast that is sent periodically from the system, but really this is what the boot receiver is for. Why are you against using it? – zgc7009 Nov 12 '14 at 16:53
  • It feels like a strange permission for me. I'd like to get the silent approach – Joaquin Iurchuk Nov 13 '14 at 00:20
  • 1
    Look at http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW and standard broadcast actions. One of those may work but you should really be receiving boot completed since that's when you want to start. – zgc7009 Nov 13 '14 at 00:48
  • Thanks. I like your proposal of looking for other broadcasts. Thanks. Maybe I should take a look to the fw's manifest. – Joaquin Iurchuk Nov 13 '14 at 00:50
  • I used Application class with shutdown receiver to achieve this http://stackoverflow.com/a/29594003/2919924 – ahmedibrahim085 Apr 12 '15 at 20:01
  • @ahmedibrahim085 I liked your proposal but I saw that also I need the boot completed permission – Joaquin Iurchuk Apr 12 '15 at 20:08
  • @joaquin You can remove it(boot completed permission ) and remove the boot broadcast class. I put them in the project just for demonstration. I thought it will be nicer if some run the program and saw the logs coming from both the Application class and the boot class as a prove that my aproach works. Then S/he can remove them later. try doing so , and tell me – ahmedibrahim085 Apr 12 '15 at 20:13

0 Answers0