Bug 863103 - Add BackgroundService.runIntentInService() utility method. r=rnewman

This commit is contained in:
Chris Peterson 2013-04-23 11:03:00 -07:00
parent 43321abf7e
commit fb8072844c
3 changed files with 12 additions and 6 deletions

View File

@ -27,6 +27,13 @@ public abstract class BackgroundService extends IntentService {
super(threadName);
}
public static void runIntentInService(Context context, Intent intent, Class<? extends BackgroundService> serviceClass) {
Intent service = new Intent(context, serviceClass);
service.setAction(intent.getAction());
service.putExtras(intent);
context.startService(service);
}
/**
* Returns true if the OS will allow us to perform background
* data operations. This logic varies by OS version.

View File

@ -4,6 +4,8 @@
package org.mozilla.gecko.background.announcements;
import org.mozilla.gecko.background.BackgroundService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -28,9 +30,6 @@ public class AnnouncementsBroadcastReceiver extends BroadcastReceiver {
return;
}
Intent service = new Intent(context, AnnouncementsBroadcastService.class);
service.putExtras(intent);
service.setAction(intent.getAction());
context.startService(service);
BackgroundService.runIntentInService(context, intent, AnnouncementsBroadcastService.class);
}
}

View File

@ -4,6 +4,7 @@
package org.mozilla.gecko.background.announcements;
import org.mozilla.gecko.background.BackgroundService;
import org.mozilla.gecko.background.common.log.Logger;
import android.content.BroadcastReceiver;
@ -24,7 +25,6 @@ public class AnnouncementsStartReceiver extends BroadcastReceiver {
}
Logger.debug(LOG_TAG, "AnnouncementsStartReceiver.onReceive().");
Intent service = new Intent(context, AnnouncementsService.class);
context.startService(service);
BackgroundService.runIntentInService(context, intent, AnnouncementsService.class);
}
}