Actions scheduled by the handler cannot be performed sequentially because the device can sleep at the moment. The best way to schedule any slow motion in the background is to use the AlarmManager system.
In this case, the code should be replaced by the following:
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(BackgroundService.this, BackgroundService.class); PendingIntent pendingIntent = PendingIntent.getService(BackgroundService.this, 1, alarmIntent, 0); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3 * 60, pendingIntent);
source share