I have basic question regarding when to unregisterListener
for sensor manager. Should it be done in onStop()
or onDestroy()
.
Usecase :
I want to record accelorometer
on click of start button and stop when user clicks stop button. the frequency of data is every minute. So I have started a timer
.
But the issue is every time the orientation
changes as per Android architecture, onStop()
gets called. In onStop()
I am cancelling the timer and unregistering the listener.
SO again if I start timer/register listener in onResume()
the frequency won't remain 1 minute and also the data gets recorded without user pressing the start button.
Can someone help me resolve this issue.
Thanks.
You may want to use a Service
to run the accelerometer data collecting in the background, communicating with it using basic intents is not too complicated.
Or, if you only want to 'survive' the rotation, when the activity gets destoryed and then rebuilt, try overriding in your Activity
the onRetainNonConfigurationInstance()
and getLastNonConfigurationInstance()
methods (read more about it here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With