I have noticed than whenever I manually kill my application by longpressing the back button of my cellphone my broadcast receiver stops working. The receiver is in charge of displaying a notification every time the user hangs up a phone call and the same is registered in the manifest.xml.
Is this the normal/expected behaviour? I thought the receiver should continue to work even if the user decides to kill my application… Is there a way to prevent this?
Here’s the manifest entry for the receiver:
<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>
There are ~7 billion people on the planet. Only you know what you mean by “kill”.
The symptoms that you are describing, though, are consistent with a “force stop”. A user normally force-stops an application by going to Settings, finding your app in the list of installed apps, and tapping on the “Force Stop” button for your app. There are some devices and firmware builds that make “Force Stop” more readily accessible than this — such devices and firmware builds were written by drooling idiots IMHO.
If your app is force-stopped, your code will never run again, until something uses an explicit
Intent to start one of your components. Usually, the user does this by tapping on your app’s icon in the home screen’s launcher. Until the user does this, your
BroadcastReceiver will not work, and there is nothing you can do about it.
Rather than using some on-device feature to “kill” your app, try terminating its process via DDMS. If your app continues to work in that case, then however you elected to “kill” your app before is doing a “force-stop”. Merely having your process be terminated, such as due to low memory conditions, should not prevent you from receiving future broadcasts.
I know that some devices (like my ASUS) are deleting static receivers when you stop an application, yours is probably one of those.
The only thing you can do is trying with emulator or other device.