Pull down the ongoing notification and click "Stop".
Bring the application to the background.
Bring the application to the foreground.
Unexpected behavior: Track recording will start again.
Cause:
Tracking state is contained in both MainActivity.mTrackingState and LocationService.mTrackingEnabled, and there is a race between them.
Opinion on the fix:
Refactor to have one source for the state that will be accessed by all interested parties (MainActivity and LocationService), and which will be the only authority to store the state into shared preferences.
For my purposes, I have created an ugly workaround that always writes to the shared preference variable and reads it in "onResume". It is not consistent, as it leaves the track button red, but at least it allows me to quickly and reliably stop track recording, as I used to unintentionally have location tracking and track recording on, draining my battery, when I was sure it should have been stopped.
The other way to stop track recording is that small "ic_record_stop" button. I think that one works properly, but I only became aware of it while searching for a resolution to this issue.
Steps to reproduce.
Unexpected behavior: Track recording will start again.
Cause: Tracking state is contained in both MainActivity.mTrackingState and LocationService.mTrackingEnabled, and there is a race between them.
Opinion on the fix: Refactor to have one source for the state that will be accessed by all interested parties (MainActivity and LocationService), and which will be the only authority to store the state into shared preferences.
For my purposes, I have created an ugly workaround that always writes to the shared preference variable and reads it in "onResume". It is not consistent, as it leaves the track button red, but at least it allows me to quickly and reliably stop track recording, as I used to unintentionally have location tracking and track recording on, draining my battery, when I was sure it should have been stopped.
The other way to stop track recording is that small "ic_record_stop" button. I think that one works properly, but I only became aware of it while searching for a resolution to this issue.
Regards, Dragan