I write this code in the onDestroy() method.
@Override
public void onDestroy()
{
MessageService.this.stopSelf();
messageThread.isRunning = false;
System.exit(0);
super.onDestroy();
}
And close the service in other Activity.
stopService(new Intent(MainOptionActivity.this,MessageService.class));
I tried many code, it can not close the service when close the background. Could anyone give me some advice? Thanks.
Here is a simple code for service class
and here is the code for testing this service
this is working just fine. Also add this code in manifest