my thread is basically a loop of some actions.
I have set a few checks in my loop, to check basically if a boolean is still true or false. The boolean is set to true when starting the service and set to false when the service is being stopped. More specifically, I set the boolean to false in onDestroy() method of my Service class.
Example:
public class MyThread extends Thread{
private boolean active;
public void setBoolean(boolean active)
this.active=active;
}
}
public class MyService extends Service{
private Mythread mythread;
@Override
public void onDestroy()
{
mythread.setBoolean(false);
}
}
The issue is that when a Service is being stopped by the system, onDestroy()
method is not called. So, how can I properly stop the thread when the service is no longer running?