Service的使用
一、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的使用的更多相关文章
- 通过AngularJS实现前端与后台的数据对接(二)——服务(service,$http)篇
什么是服务? 服务提供了一种能在应用的整个生命周期内保持数据的方法,它能够在控制器之间进行通信,并且能保证数据的一致性. 服务是一个单例对象,在每个应用中只会被实例化一次(被$injector实例化) ...
- Azure Service Fabric 开发环境搭建
微服务体系结构是一种将服务器应用程序构建为一组小型服务的方法,每个服务都按自己的进程运行,并通过 HTTP 和 WebSocket 等协议相互通信.每个微服务都在特定的界定上下文(每服务)中实现特定的 ...
- 无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同。如果服务器位于远程计算机上,请检查。。。
异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Ser ...
- C#创建、安装、卸载、调试Windows Service(Windows 服务)的简单教程
前言:Microsoft Windows 服务能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面.这 ...
- java中Action层、Service层和Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...
- 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 [ ...
- Android—Service与Activity的交互
service-Android的四大组件之一.人称"后台服务"指其本身的运行并不依赖于用户可视的UI界面 实际开发中我们经常需要service和activity之间可以相互传递数据 ...
- angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)
common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...
- IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页
因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...
- 如何利用mono把.net windows service程序迁移到linux上
How to migrate a .NET Windows Service application to Linux using mono? 写在最前:之所以用要把windows程序迁移到Linux上 ...
随机推荐
- 【SQL模板】四.插入/更新 列模板TSQL
---Name: 插入/更新 列模板.sql ---Purpose: 用于更新 数据库中 列 的脚本模板 ---Author: xx ---Time: 2015-12-18 10:26:06 ---R ...
- loadrunner12.5-添加检查点
1.点击缩略图资源管理器,找到需要添加检查点的页面. 2.选中需要添加检查点的页面,切换到快照tab,选择“树”型显示方式. 3.在响应窗口下,找到需要添加的检查点的内容,选中--右键--添加文本检查 ...
- Windows系统文件mshtml.dll
今天,在vista 32bit,sp 2,IE7的机器上跑开发的软件产品,打开IE,被测系统总是崩溃,换了一台机器,同样的配置环境,却没有重现. 同事的分析很详细,学习了 I tried this c ...
- part1:6-Linux文本编辑器vi
vi编辑器简介: vi是Linux系统的第一个全屏幕交互式编辑器:vim则是vi的升级版得到广大用户青睐. vim有三种工作模式:命令行模式.插入模式.底行模式 命令行模式常用功能键: yy:复制当前 ...
- Linux shell脚本的字符串截取
http://blog.csdn.net/gumanren/article/details/5601544 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.ha ...
- 2018.08.29 NOIP模拟 pmatrix(线性筛)
[问题描述] 根据哥德巴赫猜想(每个不小于 6 的偶数都可以表示为两个奇素数之和),定义 哥德巴赫矩阵 A 如下:对于正整数对(i,j),若 i+j 为偶数且 i,j 均为奇素数,则 Ai,j = 1 ...
- js函数预编译
function fn(a){ console.log(a); var a = 123; function a(){} console.log(a); var b = function(){} con ...
- modelsim编译altera的库
http://www.cnblogs.com/LJWJL/p/3515586.html 在modelsim的安装目录下,把配置文件modelsim.ini的只读属性去掉,然后在modelsim中运行T ...
- BSD Socket 通信
Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain ...
- The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly 上传一份代码的时候,出现了这个错误,然后就没有成功上传. 背景操作 主要是进行svn转换到git时候出错的,转换的 ...