基本信息
源码名称:android 后台定时任务 示例源码下载
源码大小:0.10M
文件格式:.zip
开发语言:Java
更新时间:2017-08-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
public class LongRunningService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
public int onStartCommand(Intent intent,int flags,int startId){
new Thread(new Runnable() {
@Override
public void run() {
Log.d("LongRunningService","executed at " new Date().toString());
//此部分就可以填写需要执行的具体功能代码,将耗时操作写于此处。效果是每隔一小时执行一次
//you can fill in this section you need to perform the specific function of the code,
// write lengthy operations in here. The effect is, every hour will perform this function once.
}
}).start();
AlarmManager manager = (AlarmManager)getSystemService(ALARM_SERVICE);
int anHour = 60*60*1000;
long triggerAtTime = SystemClock.elapsedRealtime() anHour;
Intent i= new Intent(this,AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(this,0,i,0);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,pi);
return super.onStartCommand(intent,flags,startId);
}
}