通过bindservice调用服务内部方法
来源:互联网 发布:网络直播市场能火几年 编辑:程序博客网 时间:2024/06/05 23:53
1.在服务内部定义一个方法
public void banzheng(int money){if (money < 1000){Toast.makeText(getApplicationContext(), "太少了", 1).show();} else if (money > 1000){Toast.makeText(getApplicationContext(), "太多了", 1).show();}}
2.在服务的内容定义一个中间人对象
public class MyBinder extends Binder{public void callBanZheng(int money){banzheng(money);}}
3.把定义的中间人对象放在onBind内并返回
@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stubreturn new MyBinder();}
4.在acivity的oncreate方法内调用bindService
Intent intent = new Intent(this, BanZhengService.class);conn = new MyConnection();bindService(intent, conn, BIND_AUTO_CREATE);
5.拿到中间价对象,就可以调到服务的电话
public class MyConnection implements ServiceConnection{@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {// TODO Auto-generated method stubbinder = (MyBinder) service;}@Overridepublic void onServiceDisconnected(ComponentName name) {// TODO Auto-generated method stub}}
6.在 onDestroy方法内解绑
@Overrideprotected void onDestroy() {// TODO Auto-generated method stubunbindService(conn);super.onDestroy();}
0 0
- 通过bindservice调用服务内部方法
- 通过bindService调用服务里面的方法
- android服务_通过bindService调用服务里的方法
- Android通过bindservice方式调用服务的方法
- android bindService 来调用服务中的方法
- 为什要使用BindService?为了调用服务中的方法
- 绑定服务:调用服务内部的方法
- 通过函数指针调用对象内部方法
- 通过反射调用类内部的方法
- android ,广播接受者。调用服务内部方法
- Android 服务(service)的生命周期以及利用bindservice调用服务里面的方法
- TabActivity以及ActivityGroup调用内部的StartActivity后无法bindService
- bindService调用Service里面方法的步骤
- 通过内部接口监控服务
- 方法内部调用接口
- Android--通过AIDL+反射,调用android内部隐藏的服务实现挂断电话
- Android中通过接口调用服务里的方法
- Android通过广播接收者调用服务内方法
- 小技巧C++程序输出等待
- 基于arduino制作激光电子竖琴
- 【solr】——查询的实现
- 记录Redis的一次攻击事件
- 用Android Studio编写一个“手机信息页面”程序
- 通过bindservice调用服务内部方法
- 关键段 互斥量 以及信号量
- BZOJ4771——七彩树
- HBase的核心模块介绍
- Android OkHttp完全解析
- Android进阶之路
- 阿里巴巴笔试题
- 【c#学习笔记】在一个构造方法中调用另一个构造方法的写法
- Leetcode 401