0

In my app I´m starting a Service from my Application class and I want to run that service after reboot too.

As the Application class is instanced before the actual BootReceiver according to this post

https://stackoverflow.com/a/28131215/2324388

I´m wondering if we actually need an receiver or if it is enough to have something in the manifest with BOOT_COMPLETED.

Is there any option to start the app on boot without the need of listening to the event?

Community
  • 1
  • 1
Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
  • I used Application class with shutdown receiver to achieve this http://stackoverflow.com/a/29594003/2919924 you can also add your service start intent with the application class onCreate() method to start the service after reboot without the need of listening to the event BOOT_COMPLETED. – ahmedibrahim085 Apr 12 '15 at 20:03

1 Answers1

1

Application class is a Base class for those who need to maintain global application state, what makes it unique is it's oncreate method called when the application is starting, before any activity, service, or receiver objects starts, the opposite is it is never created when any activity, service, or receiver objects are to start.. so Yes you need a receiver to listen to BOOT_COMPLETED and in the onReceive of your receiver start your service.

Elltz
  • 10,730
  • 4
  • 31
  • 59