Accelerometer Seems To Only Work For A Few Seconds?
Solution 1:
This is taken from the Android Documentation on BroadcastReceiver
.
A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.
This has important repercussions to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes.
That sounds like what is happening in your case. The BroadcastReceiver
is no longer active so the system kills the process.
To avoid this you can move the SensorChangedListener
into a Service
and then start the Service
from inside the BroadcastReceiver
. That way you will continue to receive the events.
Post a Comment for "Accelerometer Seems To Only Work For A Few Seconds?"