Hello, I have a service that runs in the background, this service should not be terminated by the Android system, but this happens after a run time.
public class VerificaCorridas extends Service {
private Timer timerAskServer;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
verifyServer();
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
timerAskServer.cancel();
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void verifyServer() {
timerAskServer = new Timer();
TimerTask askServer = new TimerTask() {
public void run() {
// Aqui é feito uma consulta ao servidor para ver se tem algo novo
};
};
timerAskServer.schedule(askServer, 0, 10000); //repete a cada 10 Seg
}
}