How does controller listen to service?
Polling. The Controller periodically asks the
Servicefor the latest data. IMHO, this option sucks, but it's certainly possible.Callbacks. The
Controllerregisters a callback object ("observer") with theService. TheServiceinvokes a method on the callback when the data changes, which in turn updates the UI. You can see an example of using that with aServicehere.Broadcast
Intents. TheServicebroadcasts anIntentviasendBroadcast()on a data change. TheControllerregisters aBroadcastReceiverusingregisterReceiver(), and thatBroadcastReceiveris notified of an incoming broadcast. This triggers the Controller to load the latest data from theService, or possibly just to get the latest data out of extras in the broadcastIntent. You can see an example of using that technique with aService
e.g.
Your onReceive() method in the BroadcastReceiver gets a Context passed, use that.
@Override
publicvoid onReceive(Context context,Intent intent){
db = newDatabase(context);//more stuff
}
Also be aware that inside a BroadcastReceiver, you are only guaranteed 10 seconds of execution time, after that, Android may kill your Receiver. So be quick with what you're doing and if the database operation is lengthy, consider using a separate Thread.
How does controller listen to service?的更多相关文章
- 深入理解--SSM框架中Dao层,Mapper层,controller层,service层,model层,entity层都有什么作用
SSM是sping+springMVC+mybatis集成的框架. MVC即model view controller. model层=entity层.存放我们的实体类,与数据库中的属性值基本保持一致 ...
- 非Controller类无法使用Service bean解决方案
尝试方案: 1 在Spring的配置文件springmvc.xml中,增加扫描项base-package="zxs.ssm.util",增加你需要使用service的类所在的包 ...
- controller层,service层,dao层(main函数,子函数,子的子函数)
controller层相当于main函数————————————————————————————————————————————————————@RequestMapping("/query ...
- SpringBoot—单元测试模板(controller层和service层)
介绍 概述 在开发过程中,我们经常会一股脑的写各种业务逻辑,经常等全部大功告成的时候,打个jar包放环境里跑跑看看能不能通,殊不知在各个业务方法中已经漏洞百出,修复一个打一个包,再继续修复,这种效 ...
- 非Controller中调用Service
1. 新增文件 package com.library.common; import org.springframework.beans.BeansException; import or ...
- spring非controller类获取service方法
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); pushMessageServ ...
- spring mvc中的service和controller中读取不到properties值
根据web.xml读取配置文件中的顺序来看 controller层和service层来自于spring mvc.xml中读取,所以必须要在spring mvc.xml中配置读取资源文件夹方式
- 【起航计划 035】2015 起航计划 Android APIDemo的魔鬼步伐 34 App->Service->Local Service Controller
Local Service Controller 是将LocalService当作“Started”Service来使用,相对于”Bound” Service 来说,这种模式用法要简单得多,Local ...
- SSM集成shiro 致使Controller无法自动注册service
由于shiro在web.xml中配置属于过滤器,其中在web.xml中的加载顺序为: <context-param>(上下文) > listener > filter > ...
随机推荐
- Windows Live Writer技巧
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:今天的内容虽然和开发技术无关,却应该和喜欢写东西的技术人员有关,比如我所有的文章都是用 ...
- MathType 常用快捷键
MathType 数学公式编辑器是广大理科生电脑上必不可少的软件!然而在大量公式时,不会巧妙使用快捷键真的是心累身累.巧妙使用MathType数学公式编辑器可加快数学符号的录入速度和效率,这将节约大量 ...
- MySQL的中文编码问题
创建表格时,怎么让表格显示中文?注意:不区分大小写 mysql> ALTER TABLE 表格的名字 CONVERT TO CHARACTER SET UTF8; 怎么让默认的数据库支持中文字符 ...
- Released Mocked Streams for Apache Kafka
Kafka Streams is a deployment-agnostic stream processing library written in Java. Even thoug ...
- Android 实现ListView中Item被单击后背景色保持高亮
今天为了解决一个需求,就是我有一个slidingDrawer,里面是一个ListView.然后,单击其中的Item,默认只是显示一个橙色背景后就恢复了.客户便有着个需求,需要单击这个Item的背景高亮 ...
- nodejs随记02
Basic认证 检查报文头中Authorization字段,由认证方式和加密值构成: basic认证中,加密值为username:password,然后进行Base64编码构成; 获取username ...
- json返回数据库的时间格式为/Date(1477294037000)/,怎样在前台进行格式化转换
方法一: 原理是取中间的数,再转换成js的Date类型 function ChangeDateFormat(val) { if (val != null) { var date = new Date( ...
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8481 Accepted: 5479 Description In an ...
- 我的c++学习(1)hello world!
// texthello.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using na ...
- jQuery Multi-TouchWipe / Multi-TouchZoom
jQuery Multi-TouchWipe / Multi-TouchZoom是小弟参照WipeTouch扩展出来的针对多点触屏划动而改写出来的Jquery插件,可以为dom上的两手指触屏划动拨入( ...