I have an android app which turns on a sensor on my device and collects data, the data is then sent via http requests and a response is returned back to the app.
However when the back button is pressed it doesn't go back to the home page of the app, instead it crashed with:
unfortunately app has stopped
And I get these errors:
If I press the back button before data gets collected then the app goes back properly to the home screen.
It seems that the ServiceConnection class is still running which is causing the error.
So it seems that pressing the back button somehow interferes with the background network activity. Given that the network activity is on its own thread, that shouldn't happen, as whatever the network access does, has nothing to do (or at least should have nothing to do) with any GUI. So: what does pressing the back button do? Do you have code that runs in that case?
If the code performs a network operation in its own thread, it may not be possible to stop it right away. You need to ensure that -whatever it is doing- has no effect on the app, and that any exception that may occur within is properly caught - which in this case apparently does not happen.