我已经在我的项目中实现了 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) {
我做错了什么?