Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register a Service that will run all the time

Tags:

android

I would like my android app service to run all the time. that is - 1. right after installation, 2. on boot 3. if its closed - it will be relaunched -

how do i achieve all of the above code-wise?

thanks!

like image 665
Himberjack Avatar asked Jan 23 '26 22:01

Himberjack


1 Answers

I am not putting the code here however you can easily find it.

  1. Right after installation use the default activity to launch the service, in case you do not have any UI then create an activity without any UI (no setContentView) and in its onCreate start the service.

  2. You need to create a broadcastReceived that listens to ACTION_BOOT_COMPLETED and call that as Service Manager. On Receiving the broadcast in that receiver just start the service again.

  3. Make your service as foreground and that should ideally take care of this scenario.

like image 134
PravinCG Avatar answered Jan 26 '26 13:01

PravinCG