Android service launched when the phone is turned off starts automatically when the phone boots

I am currently developing an Android telephony application that includes a service for processing all SIP signals to receive and receive calls.

I want this service to start exclusively when the user has correctly registered in the application. However, I observe an undesirable behavior: if the device is turned off while the application is running, the service starts automatically after the phone loads. This does not happen if the application closes when the phone is turned off.

I read about it, but no answer comes up. Can someone explain why this is happening and how to prevent it?

Thanks in advance.

+4
source share
1 answer

Thanks to CommonsWare's comment, I quickly found the answer:

[...] The only way to start a service is if someone starts it, and the OS does not do it on its own.

I was so blinded that the OS was responsible for this, that I did not notice that it was done specifically as an undocumented function inherited from the previous version of the application.

There was a BroadcastReceiver, which listened to the action android.intent.action.BOOT_COMPLETED. This receiver, among other things, restarted the service at startup when the application was not properly disconnected.

Thank you CommonsWare for your help.


Update

After the BroadcastReceiver does not listen to the BOOT_COMPLETE action, I still experience the same behavior.

, BroadcastReceiver SIP, WIFI , . Wether , , , .

- : BroadcastReceiver android.net.conn.CONNECTIVITY_CHANGE , , , , .

+1

Source: https://habr.com/ru/post/1502608/


All Articles