I have a receiver which waits for TelephonyManager.ACTION_PHONE_STATE_CHANGED
:
public void onReceive(Context context, Intent intent) {
String th
Where does this battery drain come from?
Never never never never never never never never have something in a manifest-registered BroadcastReceiver
live beyond onReceive()
. IOW, you cannot safely register a SensorListener
from a manifest-registered BroadcastReceiver
.
Please have your BroadcastReceiver
delegate work to a Service
(via startService()
), where in onStartCommand()
you register the SensorListener
. When you get a sensor reading, or after a timeout (hint: phones don't always change orientation), or in onDestroy()
(if Android decides to shut down your service), unregister the listener and call stopSelf()
to shut down the service.