一、Service的适用范围

  1.本地服务(Local Service): 应用程序的内部(单个APP)

    startServcie  stopService  stopSelf  stopSelfResult

    bindService  unbindService

  2.远程服务 (Remote  Service) :  Android系统内部应用程序之间(多个APP)

    定义IBinder的接口

  3.Service的生命周期

    

  4.startService和bindService的各自特点

    

    
   //通过ServiceConnect对象的相关方法可以得到Service的对象
    ServiceConnection conn = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName name, IBinder binder) {
    service = ((MyBinderService.MyBind)binder).getService();
    }     //通过Ibinder接口实例返回给ServiceConnect对象给启动源
    public class MyBinderService extends Service {
    private String TAG = "info";     public class MyBind extends Binder{
    public MyBinderService getService(){
    return MyBinderService.this;
    }
    }
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
    Log.i(TAG, "MyBinderService-onBind: ");
    return new MyBind();
    }
    intent = new Intent(MainActivity.this , MyBinderService.class);
    bindService(intent, conn(ServiceConnect), Service.BIND_AUTO_CREATE);

        

Service的使用的更多相关文章

  1. 通过AngularJS实现前端与后台的数据对接(二)——服务(service,$http)篇

    什么是服务? 服务提供了一种能在应用的整个生命周期内保持数据的方法,它能够在控制器之间进行通信,并且能保证数据的一致性. 服务是一个单例对象,在每个应用中只会被实例化一次(被$injector实例化) ...

  2. Azure Service Fabric 开发环境搭建

    微服务体系结构是一种将服务器应用程序构建为一组小型服务的方法,每个服务都按自己的进程运行,并通过 HTTP 和 WebSocket 等协议相互通信.每个微服务都在特定的界定上下文(每服务)中实现特定的 ...

  3. 无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同。如果服务器位于远程计算机上,请检查。。。

    异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Ser ...

  4. C#创建、安装、卸载、调试Windows Service(Windows 服务)的简单教程

    前言:Microsoft Windows 服务能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面.这 ...

  5. java中Action层、Service层和Dao层的功能区分

    Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...

  6. org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.jca:service=LocalTxCM,name=egmasDS

    17:34:37,235 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080 17:34:37,281 INFO [ ...

  7. Android—Service与Activity的交互

    service-Android的四大组件之一.人称"后台服务"指其本身的运行并不依赖于用户可视的UI界面 实际开发中我们经常需要service和activity之间可以相互传递数据 ...

  8. angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)

    common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...

  9. IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页

    因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...

  10. 如何利用mono把.net windows service程序迁移到linux上

    How to migrate a .NET Windows Service application to Linux using mono? 写在最前:之所以用要把windows程序迁移到Linux上 ...

随机推荐

  1. dede中arcurl的解析

    有时候我们需要在dede中通过$dsql查询出文章数据,并生成文章的地址. 但是dede默认的dede_archives和附加表dede_addonarticle都没有存放arcurl的字段. 说明a ...

  2. Ubuntu12.04下搭建Java环境

    1.认识需要配置的环境变量 1). PATH: 作用是指定命令搜索路径,打开/etc/environment可以看到PATH变量的值,该变量包含了一系列的路径.那些路径都是一些经常使用的系统命令的目录 ...

  3. POJ 1300.Door Man 欧拉通路

    Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2596   Accepted: 1046 Descript ...

  4. [Eclipse]Eclipse里对XML进行注释的快捷键

    eclipse中编辑java或C/C++文件时,注释的快捷键均为 "CTRL + / ",编辑xml文件时,该快捷键无效. eclipse 针对 XML 注释:CTRL + SHI ...

  5. 用Fiddler抓到的报文Content-Type: application/x-www-form-urlencoded,怎样解析?

    抓到的HTTPS请求报文,在报文头中Content-Type: application/x-www-form-urlencoded 报文体为: entrypoint=clientmanagement& ...

  6. 并发编程(五)LockSupport

    并发编程(五)LockSupport LockSupport 提供 park() 和 unpark() 方法实现阻塞线程和解除线程阻塞,实现的阻塞和解除阻塞是基于"许可(permit)&qu ...

  7. Tomcat的杂七杂八

    localhost_access_log.2016-01-15.txt  原来这里面有访问记录. /logs/catalina.2016-01-22.log 这里有显示失败的信息 2016-01-23 ...

  8. 在mac console下 执行c++文件

    1 $ g++ -o NewFileName OldFileName.cpp -o is the letter O not zero NewFileName will be your executab ...

  9. div浮停在页面最上或最下

    div{ position:fixed; bottom:0px; // top:0px; z-index:999; } bottom:0px 浮停在最下面,top:0px 浮停在最上面:z-index ...

  10. 35. Romantic Love and Ideal Romantic Relationship 爱情及理想爱情关系

    35. Romantic Love and Ideal Romantic Relationship 爱情及理想爱情关系 ① Romantic love has clear evolutionary r ...