If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.wkmf.guess.lib.service;
/*www.java2s.com*/import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
/**
* Created by ernestofndz on 07/03/14.
* <p/>
* El servicio detecta cuando ha cambiado el da para consultar el webservice y determinar si hay ms niveles disponibles
*/publicclass GuessGameService extends Service {
privatestaticboolean running = false;
// no hacemos nada
@Override
public IBinder onBind(Intent intent) {
return null;
}
// iniciamos el alarmManager para ejecutar el update cada X tiempo
@Override
publicint onStartCommand(Intent intent, int flags, int startId) {
running = true;
final Intent updater = new Intent(this, GuessGameUpdater.class);
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, updater, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 60 * 6, pendingIntent);
return START_STICKY;
}
// comprobar si est funcionando el servicio
publicstaticboolean isRunning(){
return running;
}
@Override
publicvoid onDestroy() {
running = false;
super.onDestroy();
}
}