Problem scenario: I have an android application with a statically registered broadcast receiver having intent filter registered for AIRPLANE_MODE is working fine. When I turn on the airplane mode, a toast is displayed. When I force stop my application, the broadcast receiver doesn't work which is an expected result. But now when my app crashes, still the broadcast receiver is displaying toast. So, my question is why my broadcast receiver is working even on app crash whereas it is destroyed when I force stop the application. It will be really helpful if someone could provide a clear understanding of App Force Stop scenario.
Asked
Active
Viewed 273 times
1
-
I think that a statical receiver is registered out of your app's context. Same way as you don't need to run your app for it to work. But force stopping stops everything related to your package's id. – Vladyslav Matviienko Nov 16 '17 at 13:16
-
Please go through to this answer [https://stackoverflow.com/a/12275039/5308778](https://stackoverflow.com/a/12275039/5308778) – yashkal Nov 16 '17 at 13:16
-
Hi, your answer was explanatory and so I understood the force stop case but in one of the article, i read that an app crash stops the broadcast receiver which is not happening in my case. So what happens to broadcast receiver on an app crash. – Android1005 Nov 17 '17 at 05:23
1 Answers
0
In your app, you have 4 points for starting your app: BroadcastReceiver, Activity, Service, ContentProvider.
So if you register your BroadcastReceiver in AndroidManifest, even if u make a force stop app, you will actually getting callbacks in BroadcastReceiver, because it's a point of starting app. You actually can disable BroadcastReceiver programatically by following code:
ComponentName component = new ComponentName(context, YourReceiver.class);
//Disable BroadcastReceiver
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);
//Enable BroadcastReceiver
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED , PackageManager.DONT_KILL_APP);

HeyAlex
- 1,666
- 1
- 13
- 31
-
When I am performing force stop, the broadcast receiver is not responding to system notification(AIRPLANE_MODE), which is correct. And so I expected the same result for app crash, that my broadcast receiver should not get fired once my app crashes, but that's not the scene because my broadcast receiver is responding for system notification even on app crash. How? – Android1005 Nov 17 '17 at 05:17