If a user reboots their phone while my activity is in the foreground, after the phone reboots, the activity automatically pops up again. I don’t want this to happen because none of the extra data I pass to the activity is saved, so the activity does not have the correct display.
Apparently the activity is started even before my BroadcastReceiver that has an intent-filter with android.intent.action.BOOT_COMPLETED starts.
How would I go about preventing the activity from automatically starting when the phone boots?
Edit: I use the android.intent.category.HOME category in my intent filter for my activity, which apparently is the reason for it starting up on reboot.
The
ACTION_SHUTDOWNbroadcast is supposed to go out when the device is shutting down. I say “supposed to go out”, because it assumes an orderly shutdown. If the user winds up holding the POWER button for ~10 seconds, or popping out the battery, I would assume thatACTION_SHUTDOWNis not broadcast.To control whether a component (e.g., activity) is available, you can use
PackageManagerandsetComponentEnabledSetting(). A disabled component cannot be run and is generally invisible (e.g., a disabled app widget’s<receiver>will not show up in the app widget picker).In theory, you can combine these two. However, even at the best of times, I would assume that
ACTION_SHUTDOWNbehaviors are rather time-limited (so be quick about it), and you will need to handle the “disorderly” shutdown scenarios.