AlarmManager 和 BroadcastReceiver 的简单实现,我就是无法让它运行。由于很多代码无法用日志检查(这是我通常做的),我想我会问你们。我的主要活动中的 onCreate() 方法调用:
private void setupBackupService() {
// TODO Auto-generated method stub
alarmMgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, BackupReceiver.class);
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() +
10 * 1000, 100, pIntent);
Log.i("main","hello");
}
BacupReceiver 看起来像:
public class BackupReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("BroadcastReceiver","hello");
}
}
和一份清单文件:
<receiver android:name="BackupReceiver" >
</receiver>