I need to create a BroadcastReceiver which performs certain task immediately each time the device boots up. Also, when a certain button is clicked, the receiver should stop starting on boot. Can someone help me to manage that?
I need to create a BroadcastReceiver which performs certain task immediately each time the
Share
All you need to solve the first part of your question is to make a
BroadcastReceiverfor it and declare it in your Manifest as:The
QUICKBOOT_POWERONis necessary for some devices that don’t send theBOOT_COMPLETEDbroadcast. HTC devices like to use the quickboot one instead.For the second part of your question, there are a few different ways you could accomplish this. You could simply set a value in
SharedPreferencesthat your receiver checks every time it fires, and exit immediately if the value dictates such.You could also disable the receiver in code:
You can enable it using the same method:
I am unsure of the persistence of this method. I use it in one of my apps, but it’s not for a boot receiver, and it doesn’t have to persist across boots. You’ll have to experiment with it if you want to go that route.