0
Hello I have a service that runs in the background, this service should not be finished by the Android system, but it 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
}
}
Without knowing the service code becomes difficult.
– ramaral
I will try to reduce the code to post, but can it happen? A service it is finalized by the system?
– Mateus Carvalho
Yes, it depends on how it is declared.
– ramaral
Ready posted the code
– Mateus Carvalho
For this specific case and if you do not want to use the Google cloud messaging (GCM) use a Alarmmanager with a Broadcastreceiver. Behold here an example.
– ramaral
@Mateuscarvalho este APP que você está elaborando é para Entregas Rápido?
– Sr. André Baill
No @Andrébaill
– Mateus Carvalho
@ramaral I use parse.com, it is already included the service of GCM, however there is a delay of time sometimes in the delivery of the message... That can’t happen, you can tell if it’s normal?
– Mateus Carvalho
I don’t know, I’ve never used the Parse.
– ramaral