《Android攻略》客户端和Service交互
来源:互联网 发布:什么叫淘宝流量 编辑:程序博客网 时间:2024/05/02 06:20
1)客户端实现android.content.ServiceConnection的一个子类,随着Service的启动和停止,为了获得Service的信息重载其中的抽象方法void onServiceConnected(ComponentName className,IBinder service)和
void onServiceDisconnected(ComponentName name)。当bindService(Intent,ServiceConnection,int)返回ture时,如果建立了到Service的连接,就会调用前一个方法;传递给该方法的IBinder参数与onBind(Intent)的返回值相同。如果Service连接丢失 ,就会调用后一个方法。
连接丢失通常发生在提供Service的进程崩溃或被临时终止的情况下。只要ServiceConnection实例本身没有被删除,与Service的绑定就始终处于活跃状态,当Service再次运行时会调用onServiceConnected(ComponentName,IBinder)。
2)客户端将ServiceConnection子类对象传递给bindService(Intent,ServiceConnection,int)方法。
客户端调用void unbindService(ServiceConnection conn)方法与Service断开连接。断开连接后,Service重启时,该组件也不会收到调用。如果没有其他绑定,该Service随时可以停止。
在Service可以停止Service之前,会调用服务的boolean onUnbind(Intent intent)生命周期回调方法,其中的Intent对象会传递给unbindService(ServiceConnection)。假设onUnbind没有返回ture,则销毁该服务。否则每次绑定到该Service时都调用void onRebind(Intent intent)生命周期回调方法。
- 《Android攻略》客户端和Service交互
- Android客户端和服务器交互
- android activity和service的交互介绍
- android应用Service和activity交互
- Android中远程Service和Activity交互
- android activity和service的交互介绍
- Android客户端和Internet的交互
- android客户端和服务端js交互
- android客户端和php服务简单交互
- android客户端和php服务简单交互
- Android客户端和服务器端数据交互
- android客户端和php服务简单交互
- Android客户端和服务器数据交互
- android客户端和php服务简单交互
- android客户端和webservive交互的方式
- 简单的Android服务端和客户端登录交互(客户端)
- Activity和Service交互
- 网关和客户端交互
- 精通Android3学习笔记(一)基础知识
- 拥有 RDBMS 特性的 NoSQL 数据存储
- UVA 10905 - Children's Game
- oracle 查询语句大全
- 使用MPI编译Linux平台下使用的并行SuperLU静态链接库
- 《Android攻略》客户端和Service交互
- 工作环境迁移:Ubuntu 12.04 使用笔记(一)
- 10359 - Tiling (递推,类斐波那契)
- spoj694之后缀数组
- loadrunner场景设置的方法
- Codeforces Round #189 (Div. 1)
- 深入理解C/C++ [Deep C (and C++)]
- 成为IT经理必备的十大软技能
- 扑克牌的顺子