When is it safe to use the DONT_KILL_APP to disable a component?

Viewed 75

I need to programmatically disable a BroadcastReceiver that receives the BOOT_COMPLETED action. The code below solves the problem:

packageManager.setComponentEnabledSetting(broadCastReceiverName, 
    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 
    PackageManager.DONT_KILL_APP);

I used the DONT_KILL_APP flag to prevent the system from killing the application after changing the component configuration. The issue is that the documentation for the DONT_KILL_APP flag contains the following excerpt:

Be careful when you set this since changing component states can make the containing application's behavior unpredictable.

The text is extremely vague and doesn't make it clear what problems can happen or what the correct uses are. I tested disabling a BroadcastReceiver on its onReceive() and had no problems. Disabling from a Activity also works. What makes me unsure about this solution is that the documentation doesn't describe what is the safe way to use the flag. It also says that the behavior is unpredictable. It may be working locally, but present problems in production.

Does anyone have more details on using this flag and in what scenarios is it safe to use it?

0 Answers
Related