BroadcastReceiver does not work when I kill an application

I noticed that whenever I manually kill the application by pressing the back button on my mobile phone, my broadcast receiver stops working. The receiver is responsible for displaying a notification every time a user hangs up a phone call, and the same one is registered in the manifest.xml file.

Is this normal / expected behavior? I thought that the receiver should continue to work, even if the user decides to kill my application ... Is there a way to prevent this?

Thanks.

Edit

Here's the manifest entry for the recipient:

<receiver android:name=".BroadcastReceivers.CallReceiver" android:enabled="true"> <intent-filter> <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver> 
+6
source share
2 answers

There are ~ 7 billion people on the planet. Only you know what you mean by "kill."

The symptoms you describe, however, are consistent with a "stopping power." The user usually forcibly stops the application by going to Settings, finding your application in the list of installed applications and clicking the "Force Stop" button for your application. There are some devices and firmware that make Force Stop more accessible than this β€” such devices and firmware assemblies were written by frightening IMHO idiots.

If your application is disabled, your code will never run again until something uses an explicit Intent to run one of your components. Typically, a user does this by clicking on the icon of their application in the launch pad. Until the user does this, your BroadcastReceiver will not work, and there is nothing you can do about it.

Instead of using some function on the device to β€œkill” your application, try terminating its process through DDMS. If your application continues to work in this case, then, however, you decide to β€œkill” your application before doing a β€œforced stop”. A simple process termination, for example, due to low memory conditions, should not impede future transmissions.

+9
source

I know that some devices (like my ASUS) remove static receivers when you stop the application, and yours is probably one of them. The only thing you can do is try with an emulator or other device.

0
source

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


All Articles