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的更多相关文章

  1. Spring.xml中配置注解context:annotation-config和context:component-scan简述

    XML中context:annotation-config和context:component-scan简述 <context:annotation-config/> 中文意思:<上 ...

  2. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  3. 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 ...

  4. Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别

    <context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config& ...

  5. Android 缓存目录 Context.getExternalFilesDir()和Context.getExternalCacheDir()方法

    一.基础知识 应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的.大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中.这样当该应用被卸载 ...

  6. context:exclude-filter 与 context:include-filter 转

    context:exclude-filter 与 context:include-filter 转 1 在主容器中(applicationContext.xml),将Controller的注解打消掉 ...

  7. [ERROR][org.springframework.web.context.ContextLoader][main] Context initialization failed org.sprin

    做一个SSH为基础框架的webapp小DEMO,复制了一把以前可以跑的代码,竟发现无法初始化数据源,报错如下: [ERROR][org.springframework.web.context.Cont ...

  8. <context:annotation-config> 和 <context:component-scan>的差别

    <context:annotation-config> is used to activate annotations in beans already registered in the ...

  9. <context:annotation-config> 跟 <context:component-scan>诠释及区别

    <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注 ...

随机推荐

  1. NEU 1681: The Singles

    题目描述 The Signals’ Day has passed for a few days. Numerous sales promotion campaigns on the shopping ...

  2. 织梦CMS首页、列表页文章如何调出该文章TAG标签?

    1.如果是dedecms v5.7版本直接使用标签 [field:id function=GetTags(@me)/] 就可以调用出来了.只不过不带连接的. 2.如果需要连接请注释掉include/h ...

  3. 教你开发jQuery插件

    jQuery插件开发模式 软件开发过程中是需要一定的设计模式来指导开发的,有了模式,我们就能更好地组织我们的代码,并且从这些前人总结出来的模式中学到很多好的实践. 根据<jQuery高级编程&g ...

  4. linux初级学习笔记七:linux用户管理,密码和组命令详解!(视频序号:04_1)

    本节学习的命令: 用户管理命令:useradd,userdel,id,finger,usermod,chsh,chfn,passwd,pwck, 组管理命令:groupadd,groupmod,gro ...

  5. html5--6-52 动画效果-过渡

    html5--6-52 动画效果-过渡 实例 @charset="UTF-8"; div{ width: 300px; height: 150px; margin: 30px; f ...

  6. Nth prime & numbers of primes (模板)

    都是取的模板,这几天做的素数题挺多的,所以整理了放在这里,感觉有一天回用到的! SPOJ:Nth Prime:     求第N个素数,N<1e9. #include<bits/stdc++ ...

  7. CodeForces937B:Vile Grasshoppers(素数性质)

    The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. ...

  8. UIWindow学习

    写在前面 本文内容绝大部分都参考唐巧大神的<iOS开发进阶>,只是结合不是特别长的开发经验加以补充:最后基于UIWindow自定义了一个类似于微信的ActionSheet. UIWindo ...

  9. MP4V2库与MP4AV库编译

    最近在开发一个将RTP流存储为MP4文件的功能.其中针对MP4文件读写,用到了两个开源的库.其中MP4V2用于数据的读写,MP4AV用于对其中的数据帧进行分析. MP4V2和MP4AV都是开源项目MP ...

  10. windows下安装RabbitMQ消息服务器 + 读写队列

    RabbitMQ是什么 ? RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. 1:安装RabbitMQ需要先安装Erla ...