IntentService+BroadcastReceiver 实现定时任务
效果图:![]()
AlramIntentService package com.example.admin.water; import android.app.AlarmManager;import android.app.IntentService;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.os.SystemClock; public class AlramIntentService extends IntentService { public AlramIntentService() { super("AlramIntentService"); } @Override protected void onHandleIntent( Intent intent) { new Thread(new Runnable() { @Override public void run() { NotificationUtils.remindUserBecauseCharging(AlramIntentService.this); } }).start(); AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE); long triggerAtTime=SystemClock.elapsedRealtime()+60*1000; Intent i=new Intent(this,AlarmReceiver.class); PendingIntent pendingIntent=PendingIntent.getBroadcast(this,0,i,0); alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,pendingIntent); }}
AlarmReceiver
package com.example.admin.water; import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent; public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { intent=new Intent(context,AlramIntentService.class); context.startService(intent); }} 最后在MainActivity加上Intent i=new Intent(this,AlramIntentService.class);startService(i);
github项目源码:https://github.com/NeoWu55/Android-Water
IntentService+BroadcastReceiver 实现定时任务的更多相关文章
- [Xamarin.Android] 結合Windows Azure與Google cloud message 來實現Push Notification (转帖)
這一篇要討論如何使用Xamarin.Android 整合GCM以及Windows Azure來實作Android手機上的推播通知服務. 這篇文章比較著重概念的部分,在開始讀這篇之前,也可以先參考一下X ...
- AlarmManager定时闹钟
一.AlarmManager介绍: AlarmManager是Android中常用的一种系统级别的提示服务,在特定的时刻为我们广播一个指定的Intent.简单的说就是我们设定一个时间,然后在该时间到来 ...
- 服务 IntentService 前台服务 定时后台服务
Activity public class MainActivity extends ListActivity { private int intentNumber = 0; @Ove ...
- Android IntentService完全解析 当Service遇到Handler
一 概述 大家都清楚,在Android的开发中,凡是遇到耗时的操作尽可能的会交给Service去做,比如我们上传多张图,上传的过程用户可能将应用置于后台,然后干别的去了,我们的Activity就很可能 ...
- android: 后台执行的定时任务
Android 中的定时任务一般有两种实现方式,一种是使用 Java API 里提供的 Timer 类, 一种是使用 Android 的 Alarm 机制.这两种方式在多数情况下都能实现类似的效果,但 ...
- Android IntentService 与Alarm开启任务关闭任务
1:MyService public class MyService extends IntentService{ AlarmManager alarmManager = null; PendingI ...
- Android Service 通过 BroadcastReceiver 更新Activity UI
1:MainActivity.java public class MainActivity extends Activity { private TextView tvInfo = null; pri ...
- AlarmReceiver 与IntentService的使用
1:GetSmsService.java public class GetSmsService extends IntentService{ private AlarmManager alarmMan ...
- 【九】注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)
上一篇我们简单的介绍了一下RoboGuice的使用([八]注入框架RoboGuice使用:(Your First Injected Fragment)),今天我们来看下服务(Service)和广播接受 ...
随机推荐
- Android Studio 学习(七)通知
导入support- -v4 1.进入 file-project structure 2.左边选择app 3.右边选择dependencies 4.左下角可以看到一个加号,点击选择Library de ...
- ArcGIS Server较早版本切片迁移注意事项
原创文章,转载须标明出处自: http://www.cnblogs.com/gisspace/p/8286838.html -------------------------------------- ...
- Android .9.png 的介绍
概述 .9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法.点九图是一种可拉伸的位图,android会自动调整它的大小,来使图像在充当背景时可以 ...
- selenium-确认进入了预期页面(四)
selenium确认进入了预期页面 在自动化操作中,浏览器每次进入一个新的需要,都需要确认该页面是否打开或打开的页面是否是预期的页面 需要进行确认页面后方可进行下一步操作 确认页面有很多中方法,像笔者 ...
- ASP.NET -- WebForm -- ScriptManager 类
ASP.NET -- WebForm -- ScriptManager 类 通过 ScriptManager 可注册随后将作为页面一部分呈现的脚本. 1. 注册并立即执行脚本. --RegisterS ...
- LeetCode算法题-Design LinkedList(Java实现)
这是悦乐书的第300次更新,第319篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第168题(顺位题号是707).设计链表的实现.您可以选择使用单链表或双链表.单链表中的 ...
- 《精通Spring+4.x++企业应用开发实战》读后感
引言 还记得大三时上培训班的是时候,当时的培训老师说自己是本地讲解spring最好的讲师,但是后来等我实习了看了<Spring 3.x 企业应用开发实战>以及后续版本<精通Sprin ...
- 怎样保证socket.recv接收完数据
最近在使用python进行网络编程开发一个通用的tcpclient测试小工具.在使用socket进行网络编程中,如何判定对端发送一条报文是否接收完成,是进行socket网络开发必须要考虑的一个问题.这 ...
- Storm入门(三)HelloWorld示例
一.配置开发环境 storm有两种操作模式: 本地模式和远程模式.使用本地模式的时候,你可以在你的本地机器上开发测试你的topology, 一切都在你的本地机器上模拟出来; 用远程模式的时候你提交的t ...
- Hystrix是个什么玩意儿
1. 什么是Hystrix Hystrix是Netflix的一个开源框架,地址如下:https://github.com/Netflix/Hystrix 中文名为“豪猪”,即平时很温顺,在感受到危险的 ...