I use a service and within this service I have a timer, which sends every minute a message to my TCP/IP-Server.
public void keepAlive() {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
Gson gson = new Gson();
String message = gson.toJson(new StillAlive(Mode.STILLALIVE));
sendMessage(message);
Log.d("TCP-SEND", message);
} catch(Exception e) {
Log.e("TCP1", e.getMessage());
}
}
}, 60000, 60000);
}
But when my mobile phone locks. Or I press the button to turn off the display, my service stops sending these Messages.
What I am not sure about is, if the service stops, when turning the display off or if just the timer stops because of any reason I am not aware of.
Does anyone know if a Timer stops in this situation? Or does a service stop?
Would appreciate some help! :-)