I have a service running (Socket), this is how i start the service.
Intent s = new Intent(this, Socket.class);
startService(s);
in every activity i check for the user to select the home button, as soon as the home button is clicked i need to destroy the socket, so i have the below code on every activity in my app:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_HOME)
{
Intent s = new Intent(this, Socket.class);
stopService(s);
}
return true;
}
but this doesn't seem to stop my service?
Am i missing something? I need to destroy my service as soon as the home button is clicked.