I tried to set a background "service" that, every minute, triggers an activity that do some stuff. I found the Alarm Manager class and I wrote this code based on Android doc:
Intent backg = new Intent(getApplicationContext(), CheckConnectivity.class);
boolean backgRunning = (PendingIntent.getBroadcast(getApplicationContext(), 0, backg, PendingIntent.FLAG_NO_CREATE) != null);
if(!backgRunning) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, backg, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 60000, pendingIntent);
}
but the service is not triggered every minute, but it seems working only when the screen is off. Do you know why? What am I doing wrong?