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 > ...
随机推荐
- Java Web 项目获取运行时路径 classpath
假设资源文件放在maven工程的 src/main/resources 资源文件夹下,源码文件放在 src/main/java/下, 那么java文件夹和resources文件夹在运行时就是class ...
- HTTP访问的两种方式(HttpClient+HttpURLConnection)整合汇总对比(转)
在Android上http 操作类有两种,分别是HttpClient和HttpURLConnection,其中两个类的详细介绍可以问度娘. HttpClient: HttpClient是Apache ...
- 函数调用关于从Ring3转到Ring0 ESP堆栈变化
在ring0堆栈获取ring3堆栈方式 第一种方式 [esp+4] == [esp+参数个数*4+4] 如果这里不相等就需要用第二种方式 [[esp+参数个数*4+8]] 这里面的值就是Ring3的堆 ...
- Linux编程(3) MakeFile
1. 在Linux中,make工具可以维护程序模块关系和生成可执行程序.它可根据程序模块的修改情况重新编译链接生成中间代码或最终的可执行程序.执行make命令,需要一个名为Makefile的文本文件, ...
- js循环添加事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- winmail服务器启动失败 无法启动
1.解决句柄问题:打开命令行:开始 -> 运行-> 输入 cmd -> 确定.切换命令目录至winmail的服务目录,我的是:E:\htdocs\Winmail\server\> ...
- DSP using MATLAB 示例Example3.7
上代码: x1 = rand(1,11); x2 = rand(1,11); n = 0:10; alpha = 2; beta = 3; k = 0:500; w = (pi/500)*k; % [ ...
- node.js整理 01代码的组织和部署
模块 require(函数) 用于在当前模块中加载和使用别的模块,传入一个模块名,返回一个模块导出对象. 模块名可使用相对路径(以./开头),或者是绝对路径(以/或C:之类的盘符开头:注意单个模块名默 ...
- jade学习02
模版继承 ; block,extends ;如果是原生html文件的话,后缀html //layout.jade doctype html html head meat(charset='utf-8' ...
- CSS3-基于浮动的布局,响应式WEB设计,定位网页上的元素,设计打印页面的css技术
基于浮动的布局: 1.除非图片设置了宽度,否则始终应该要对浮动的图片设置一个宽度,这样可以让浏览器给其他内容腾出环绕的空间 2.当侧边栏的高度与主内容区的高度不一致的时候,可以用个margin进行调整 ...