Improved perf in reminder scheduling - sleep for a bit to prevent ANR in scheduling service, don't print out date when doing reminder scheduling

pull/14/head
Tim Su 14 years ago
parent 211819b21a
commit a30fbce42d

@ -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

@ -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);
}

Loading…
Cancel
Save