client怎样调用IBinder接口对象
代码:
public void funclick(View view){
Intent _intent = new Intent(MainActivity.this,MyService.class);
bindService(_intent, conn, BIND_AUTO_CREATE);
}
private ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName arg0) {
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
String mynameStr = ((MyBinder)service).helloWorld("bitch");
Log.e("mynameStr", mynameStr+"~");
}
};
对于这种一个service.有什么不同呢。服务端的代码能够參照我上篇博文,通过打印log发现。onStart或者onstartCommand并没有被调用哦。
到此,我们仍然不会满足,由于我们仅仅是调用了MyBinder中的方法,并没有调用Myservice方法嘛。所以。我们要添加一个返回MyserVice的方法:
package com.example.mydownload; import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log; //实现接口中的方法 public class MyService extends Service {
//接口对象
IBinder mybBinder = new MyBinder(); class MyBinder extends Binder{
<span style="color:#ff0000;">public MyService getMyService(){
return MyService.this;
}</span>
public String helloWorld(String name){
return name;
}
} @Override
public void onCreate() {
Log.e("log", "onCreate");
super.onCreate();
}
Log.e("log", "hello,bitch!"); @Override
public void onDestroy() {
Log.e("log", "onDestroy");
super.onDestroy();
} @Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("log", "onStartCommand");
return super.onStartCommand(intent, flags, startId);
} @Override
public IBinder onBind(Intent arg0) {
return mybBinder;
} }
然后改动client代码:
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
((MyBinder)service).getMyService().helloService();
}
client怎样调用IBinder接口对象的更多相关文章
- 服务端怎样暴露IBinder接口对象
服务端怎样暴露IBinder接口对象: package com.example.mydownload; import android.app.Service; import android.conte ...
- web service client端调用服务器接口
打开项目的web service client 其中wsdl URL http://www.51testing.com/html/55/67755-848510.html 去这里面查找一些公开的 ...
- spring cloud关于feign client的调用对象列表参数、设置header参数、多环境动态参数试配
spring cloud关于feign client的调用 1.有些场景接口参数需要传对象列表参数 2.有些场景接口设置设置权限等约定header参数 3.有些场景虽然用的是feign调用,但并不会走 ...
- Android系统进程间通信(IPC)机制Binder中的Client获得Server远程接口过程源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6633311 在上一篇文章中,我 们分析了And ...
- 【起航计划 037】2015 起航计划 Android APIDemo的魔鬼步伐 36 App->Service->Remote Service Binding AIDL实现不同进程间调用服务接口 kill 进程
本例和下个例子Remote Service Controller 涉及到的文件有RemoteService.java ,IRemoteService.aidl, IRemoteServiceCallb ...
- WebApi接口 - 如何在应用中调用webapi接口
很高兴能再次和大家分享webapi接口的相关文章,本篇将要讲解的是如何在应用中调用webapi接口:对于大部分做内部管理系统及类似系统的朋友来说很少会去调用别人的接口,因此可能在这方面存在一些困惑,希 ...
- php中创建和调用webservice接口示例
php中创建和调用webservice接口示例 这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...
- 关于使用axis调用webservice接口方法
1.概述: 我们有时候会调用webserviec接口,我们向接口发送请求参数,从接口接收返回值. 2.形式: package client; import org.apache.axis.client ...
- Java调用第三方接口示范
在项目开发中经常会遇到调用第三方接口的情况,比如说调用第三方的天气预报接口. 使用流程[1]准备工作:在项目的工具包下导入HttpClientUtil这个工具类,或者也可以使用Spring框架的res ...
随机推荐
- hdu 5875(单调栈)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- CTF中的EXP编写技巧 zio库的使用
zio库没有提供文档 这个是官方给出的一个例子程序 from zio import * io = zio('./buggy-server') # io = zio((pwn.server, 1337) ...
- [原创] 基于RDP的桌面广播
之前写过一篇使用C# UDP 组播技术做的桌面广播实现, C# 使用UDP组播实现局域网桌面共享.最终效果差强人意,UDP包在不同的交换机上发送还会出现发送失败的情况,所以又重新研究了一些新的方法,包 ...
- php简明学习教程
1.变量 <?php //变量声明(php变量无需单独创建,变量会在第一次赋值时创建) $a = 1; //弱类型(php变量会根据其值自动转换为相应的数据类型) $a = "a&qu ...
- POJ 2019 Cornfields [二维RMQ]
题目传送门 Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7963 Accepted: 3822 ...
- Django Restframework 实践(一)
具备以下知识: django http://www.cnblogs.com/menkeyi/p/5882464.html http://www.cnblogs.com/menkeyi/p/588245 ...
- GC参数
串行收集器 串行收集器(Serial),是一个相对比较老的回收器,但是它的效率在回收器中相对较好,并且比较稳定.他在进行垃圾回收的过程中,使得应用暂时被挂起,然后启用单条线程去做垃圾回收,所以在进行垃 ...
- 【51Nod 1238】最小公倍数之和 V3
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1238 设\(A(n)=\sum\limits_{i=1}^n\frac{ ...
- 【BZOJ1098】[POI2007]办公楼biu
题目一开始看以为和强联通分量有关,后来发现是无向边,其实就是求原图的补图的联通块个数和大小.学习了黄学长的代码,利用链表来优化,其实就是枚举每一个人,然后把和他不相连的人都删去放进同一个联通块里,利用 ...
- CF1051D Bicolorings dp
水题一道 $f[i][j][S]$表示$2 * i$的矩形,有$j$个联通块,某尾状态为$S$ 然后转移就行了... #include <vector> #include <cstd ...