am 0833b3cb
: Merge "Fix alarm bug"
* commit '0833b3cbae69c07dac3623b8a44743761f4b6e8c': Fix alarm bug
This commit is contained in:
commit
72ca59bc2a
1 changed files with 6 additions and 19 deletions
|
@ -22,6 +22,7 @@ import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||||
|
|
||||||
|
@ -79,28 +80,14 @@ public final class UploaderService extends IntentService {
|
||||||
*/
|
*/
|
||||||
public static void cancelAndRescheduleUploadingService(final Context context,
|
public static void cancelAndRescheduleUploadingService(final Context context,
|
||||||
final boolean needsRescheduling) {
|
final boolean needsRescheduling) {
|
||||||
final PendingIntent pendingIntent = getPendingIntentForService(context);
|
final Intent intent = new Intent(context, UploaderService.class);
|
||||||
|
final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||||
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(
|
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(
|
||||||
Context.ALARM_SERVICE);
|
Context.ALARM_SERVICE);
|
||||||
cancelAnyScheduledServiceAlarm(alarmManager, pendingIntent);
|
|
||||||
if (needsRescheduling) {
|
|
||||||
scheduleServiceAlarm(alarmManager, pendingIntent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PendingIntent getPendingIntentForService(final Context context) {
|
|
||||||
final Intent intent = new Intent(context, UploaderService.class);
|
|
||||||
return PendingIntent.getService(context, 0, intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void cancelAnyScheduledServiceAlarm(final AlarmManager alarmManager,
|
|
||||||
final PendingIntent pendingIntent) {
|
|
||||||
alarmManager.cancel(pendingIntent);
|
alarmManager.cancel(pendingIntent);
|
||||||
|
if (needsRescheduling) {
|
||||||
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()
|
||||||
|
+ UploaderService.RUN_INTERVAL, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleServiceAlarm(final AlarmManager alarmManager,
|
|
||||||
final PendingIntent pendingIntent) {
|
|
||||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, UploaderService.RUN_INTERVAL,
|
|
||||||
pendingIntent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue