diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderSchedulingService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderSchedulingService.java index 78671a075..aa5a517ed 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderSchedulingService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderSchedulingService.java @@ -6,6 +6,7 @@ import android.os.IBinder; import android.util.Log; import com.todoroo.andlib.service.ContextManager; +import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.alarms.AlarmService; /** @@ -17,18 +18,34 @@ import com.todoroo.astrid.alarms.AlarmService; public class ReminderSchedulingService extends Service { /** Receive the alarm - start the synchronize service! */ - @SuppressWarnings("nls") @Override - public void onStart(Intent intent, int startId) { - ContextManager.setContext(this); + public int onStartCommand(Intent intent, int flags, int startId) { + ContextManager.setContext(ReminderSchedulingService.this); + + new Thread(new Runnable() { + @Override + public void run() { + delaySchedulingToPreventANRs(); + scheduleReminders(); + + stopSelf(); + } + }).start(); + + return START_NOT_STICKY; + } + + @SuppressWarnings("nls") + private void scheduleReminders() { try { ReminderService.getInstance().scheduleAllAlarms(); AlarmService.getInstance().scheduleAllAlarms(); } catch (Exception e) { Log.e("reminder-scheduling", "reminder-startup", e); } - - stopSelf(); + } + private void delaySchedulingToPreventANRs() { + AndroidUtilities.sleepDeep(5000L); } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java index 01576e665..05596f3f7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java @@ -24,6 +24,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Preferences; @@ -354,7 +355,8 @@ public final class ReminderService { if(time < DateUtilities.now()) time = DateUtilities.now() + 5000L; - Log.e("Astrid", "Alarm (" + task.getId() + ", " + type + + if(Constants.DEBUG) + Log.e("Astrid", "Alarm (" + task.getId() + ", " + type + ") set for " + new Date(time)); am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); }