0

我已经在我的项目中实现了 Commonsware WakefulIntentService jar 文件。

我设置了新的警报如下:

Intent intent = new Intent(context, AlarmReceiver.class);

PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);

// Get the AlarmManager service
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

// CONSTANT.ALARM_TIME is set to 300000
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,   SystemClock.elapsedRealtime()+CONSTANT.ALARM_TIME, CONSTANT.ALARM_TIME, pi);

我设置广播接收器如下:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.commonsware.cwac.wakeful.WakefulIntentService;

public class AlarmReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    WakefulIntentService.sendWakefulWork(context, AlarmService.class);
  }
}

我已经调试了这个设置,当我在 AlarmReceiver 类中设置断点时,它会触发。

但是,doWakeFulWork 中有一个断点,它永远不会到达那里。

import com.commonsware.cwac.wakeful.WakefulIntentService;

public class AlarmService extends WakefulIntentService implements OFDelegate {
private MMApp myApp;
private Account _currentAccount;
private ArrayList<Thread> _threads;

private static final String SHOW_TIME_FORMAT = "h:mma";

private final static String CLASS_NAME = AlarmService.class.getName();

public AlarmService() {
    super("AlarmService");
}

@Override
protected void doWakefulWork(Intent intent) {

我做错了什么?

4

1 回答 1

0

@Commonsware 是正确的。我在清单中有条目,但有一个错字。一旦我纠正了那个错字,doWakefulWork 就被正确调用了。感谢@Commonsware 的帮助和一个很棒的图书馆。强烈推荐!

于 2012-11-24T14:55:32.037 回答