I am created a service but not able to start service when app is going to background, foreground and reboot tv.

I have created a service project, and it’s run in the background when the app is started. But the app is going to the background or foreground or rebooting the TV; at that time, my service is not started.

Can you please give a sample so I can create a service where we can set my background service to run in the background, foreground and wake up the TV?

Basically, the app is caller and the service is callee. A service can only be started when the app is in the foreground. And the app can only be launched by the user. Thank you.