小编por*_*cho的帖子

使用IntentService中的ContentProvider

我在使用IntentService的ContentProvider时遇到问题.

我计划在我的应用程序中使用IntentService在手机完成启动时重新安排一些警报,但首先我需要从ContentProvider中提取一些数据.根据这些 链接,我可以通过注册BroadcastReceiver并从那里启动IntentService来实现这一点.这就是我做的:

OnBootReceiver.java

public class OnBootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent scheduleServiceIntent = new Intent(context, ScheduleService.class);
    context.startService(scheduleServiceIntent);
}
Run Code Online (Sandbox Code Playgroud)

ScheduleService.java

public class ScheduleService extends IntentService implements Loader.OnLoadCompleteListener<Cursor> {

private AlarmManager alarmManager;

@Override
public void onCreate() {
    super.onCreate();

    alarmManager = (AlarmManager) this.getApplicationContext().getSystemService(Context.ALARM_SERVICE);

}

@Override
protected void onHandleIntent(Intent intent) {
    String[] projection = new String[] {
    Contract._ID,
            Contract.START_TIME,
    Contract.DATE,
            Contract.NAME,
            Contract.TYPE};

    mCursorLoader = new CursorLoader(this, MyContentProvider.MyURI,
            projection, selection, selectionArgs, SOME_ID);
    mCursorLoader.registerListener(ID, this);
    mCursorLoader.startLoading(); …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider android-broadcast android-intentservice

1
推荐指数
1
解决办法
870
查看次数