I want to use a service that run in background indefinitely and call a method every 10 minute and its running even app killed
How to create it?
you could write a background Service: Running in a Background Service
and start the service every 10-11 min (cause of AlarmManager power saving behaviour), or with exact timing (needs to shedule next execution every time) with AlarmManager.setExact
Example:
private static PendingIntent createClockIntent(Context context) {
Intent intent = new Intent(context.getString(R.string.widget_broadcast_clock_update));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 1,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
public static void startClockAlarm(Context context) {
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
clockIntent = createClockIntent(context);
alarmManager.setRepeating(AlarmManager.RTC, 0,
600000, clockIntent);
}