I am struggling with an Android app to handle things new to me. I created a thread, persistent message subscriber, in my app waiting for the messages from server in the background. When I exit my app, the thread is still working. Actually, the thread try to connect again and again when it fails to connect to server. So I want to check my app is down or stil alive, otherwise I want to make my app send some message to the thread to stop before it goes down.
What ways would be there to do that in Android?
You cannot destroy. Android will only stop the thread when required. You cannot stop or destroy it.
Instead try like this: Set some flag in thread, to check when it should run and when it should stop. Like this:
Now in onstop of your activity
Change the bool value to
false: