AJPFX简述Context.startService()和Context.bindService
Context.startService()和Context.bindService
服务不能自己运行,需要通过调用Context.startService()或Context.bindService()方法启动服务。这两个方法都可
以启动Service,但是它们的使用场合有所不同。
1.使用startService()方法启用服务,调用者与服务之间没有关连,即使调用者退出了,服务仍然运行。
使用bindService()方法启用服务,调用者与服务绑定在了一起,调用者一旦退出,服务也就终止。
2.采用Context.startService()方法启动服务,在服务未被创建时,系统会先调用服务的onCreate()方法,
接着调用onStart()方法。如果调用startService()方法前服务已经被创建,多次调用startService()方法并
不会导致多次创建服务,但会导致多次调用onStart()方法。
采用startService()方法启动的服务,只能调用Context.stopService()方法结束服务,服务结束时会调用
onDestroy()方法。
3.采用Context.bindService()方法启动服务,在服务未被创建时,系统会先调用服务的onCreate()方法,
接着调用onBind()方法。这个时候调用者和服务绑定在一起,调用者退出了,系统就会先调用服务的onUnbind()方法,
。接着调用onDestroy()方法。如果调用bindService()方法前服务已经被绑定,多次调用bindService()方法并不会
导致多次创建服务及绑定(也就是说onCreate()和onBind()方法并不会被多次调用)。如果调用者希望与正在绑定的服务
解除绑定,可以调用unbindService()方法,调用该方法也会导致系统调用服务的onUnbind()-->onDestroy()方法。
AJPFX简述Context.startService()和Context.bindService的更多相关文章
- Spring.xml中配置注解context:annotation-config和context:component-scan简述
XML中context:annotation-config和context:component-scan简述 <context:annotation-config/> 中文意思:<上 ...
- [转载]Difference between <context:annotation-config> vs <context:component-scan>
在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...
- EF How to use context.Set and context.Entry, which ships with EF4.1 ?
How to use context.Set and context.Entry, which ships with EF4.1 ? Hello, I am trying to implement a ...
- Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别
<context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config& ...
- Android 缓存目录 Context.getExternalFilesDir()和Context.getExternalCacheDir()方法
一.基础知识 应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的.大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中.这样当该应用被卸载 ...
- context:exclude-filter 与 context:include-filter 转
context:exclude-filter 与 context:include-filter 转 1 在主容器中(applicationContext.xml),将Controller的注解打消掉 ...
- [ERROR][org.springframework.web.context.ContextLoader][main] Context initialization failed org.sprin
做一个SSH为基础框架的webapp小DEMO,复制了一把以前可以跑的代码,竟发现无法初始化数据源,报错如下: [ERROR][org.springframework.web.context.Cont ...
- <context:annotation-config> 和 <context:component-scan>的差别
<context:annotation-config> is used to activate annotations in beans already registered in the ...
- <context:annotation-config> 跟 <context:component-scan>诠释及区别
<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注 ...
随机推荐
- [转]GPS NEMA 0183协议
一. NMEA0183标准语句(GPS常用语句) $GPGGA例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000 ...
- JS DOM1核心概要1
节点:XML和HTML文档都是有节点构成的结构,每段标记都可以通过节点来表示: 节点类型: 元素节点(常用) 属性节点(常用) 文本节点 注释节点 文档节点 进程节点 文档类型节点 等... 了解节点 ...
- [CQOI 2015] 任务查询系统
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3932 [算法] 首先 , 我们可以将(Si , Ei , Pi)转化为在Si处加入P ...
- css原生变量 var
css 变量的支持情况: 在pc端支持还不错,ie不支持,移动端也不支持,大概这就是css变量没有广泛使用的原因吧 CSS预编译工具Sass/Less/Stylus的便捷之处就是可以定义变量,方便代码 ...
- 利用记事本和cmd进行java编程(从安装IDE--编译--运行)
java 最大特点---跨平台 所谓的跨平台性,是指软件可以不受计算机硬件和操作系统的约束而在任意计算机环境下正常运行.这是软件发展的趋势和编程人员追求的目标.之所以这样说,是因为计算机硬件的种类繁多 ...
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...
- 个人项目开发PSP实践-MyWCprj
MyWCprj.exe Github仓库地址 1. What is MyWCprj.exe? wc是linux下一个非常好用的代码统计小工具,可以通过 -c .-w .-l等选项分别进行对指定文件的代 ...
- E20170417-sl
recursive adj.递归的 strategy n.战略
- Codeforces Round #408 (Div. 2) D. Police Stations(最小生成树+构造)
传送门 题意 n个点有n-1条边相连,其中有k个特殊点,要求: 删去尽可能多的边使得剩余的点距特殊点的距离不超过d 输出删去的边数和index 分析 比赛的时候想不清楚,看了别人的题解 一道将1个联通 ...
- hihoCoder搜索二·骑士问题
#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> ...