android 计时器服务,启动时使用计时器/alarmclock,更新服务_android_开发99编程知识库...

我找到了問題的答案:private boolean service_started=false;

private PendingIntent mAlarmSender;

@Override

public void onReceive(Context context, Intent intent) {

if(!service_started){

//Create an IntentSender that will launch our service, to be scheduled

//with the alarm manager.

mAlarmSender = PendingIntent.getService(context,

0, new Intent(context, UpdateService.class), 0);

//We want the alarm to go off 30 secs from now.

long firstTime = SystemClock.elapsedRealtime();

//Schedule the alarm!

AlarmManager am = (AlarmManager)context.getSystemService(context.ALARM_SERVICE);

am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,

firstTime,30*1000, mAlarmSender);

service_started=true;

}

}

最後,我的問題是,我沒有按如下方式獲得上下文:(AlarmManager)getSystemService(ALARM_SERVICE);

更改為( AlarmManager ) 上下文。getSystemService ( 上下文。alarm_service ) ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值