使用ADIL访问远程服务
来源:互联网 发布:数学建模知乎 编辑:程序博客网 时间:2024/05/16 10:10
1.新建aidl文件
2.Build->Make Project
在该目录下可以发现生成后的IMyAidlInterface.java文件。
3.新建Service并实现IMyAidlInterface定义的方法,onBind中返回实例。
public class MyRemoteService extends Service { public MyRemoteService() { } IMyAidlInterface.Stub myAidlInterface = new IMyAidlInterface.Stub() { @Override public String SayHello(String world) throws RemoteException { return world; } }; @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. return myAidlInterface; }}4.Manifest 中修改定义
<service android:name=".MyRemoteService" android:enabled="true" android:exported="true" android:process=":remote" > <intent-filter> <action android:name="my.test.com.servicedemo.MyService" /></intent-filter></service>5.Activity中调用
楼主下午一直报null因为在bindService后直接调用myAidlInterface 的方法了,此时应该并没有执行完onServiceConnected,
所以最好在onServiceConnected后再调用方法!
intent_aidl = new Intent(this, MyRemoteService.class);
bindService(intent_aidl, aidl_ServiceConnection, BIND_AUTO_CREATE);
private IMyAidlInterface myAidlInterface = null;ServiceConnection aidl_ServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { Log.i("MainActivity", "ComponentName:"+componentName); myAidlInterface = (IMyAidlInterface.Stub.asInterface(iBinder)) ; if(myAidlInterface==null) Log.i("MainActivity", "myAidlInterface==null"); else { try { String temp=myAidlInterface.SayHello("fuck uuuuuuu!!!!!!"); Toast.makeText(MainActivity.this,temp,Toast.LENGTH_SHORT).show(); } catch (RemoteException e) { e.printStackTrace(); } } } @Override public void onServiceDisconnected(ComponentName componentName) { }};
0 0
- 使用ADIL访问远程服务
- android学习笔记之ADIL,Parcelable和远程服务
- jboss 远程访问服务
- RAS--远程访问服务
- Java访问远程服务
- 访问远程服务
- windows2003服务---远程访问服务
- Service之跨进程调用服务ADIL
- 使用Spring进行远程访问与Web服务
- 通过Spring使用远程访问和web服务(转载)
- 通过Spring使用远程访问和web服务
- 通过Spring使用远程访问和web服务
- 使用Spring进行远程访问(rmi)与Web服务
- 通过Spring使用远程访问和web服务
- 通过Spring使用远程访问和web服务
- 使用jsch-spring-boot在本地访问远程云服务
- 本地Manager访问远程服务
- JDK_jvisualvm访问远程weblogic服务
- Java习惯用法总结
- Android中的错误解决。Plugin is too old
- UILabel详解
- HDU【2795】Billboard
- [图形学]光栅直线算法
- 使用ADIL访问远程服务
- ios tcp multipath
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat使用详解
- chmod----改变一个或多个文件的存取模式(mode)
- 2016.1.25 ACM算法讨论群 群赛
- 欢迎使用CSDN-markdown编辑器
- 补充 十进制转化十六进制
- 猫猫学Swift之变量和常量(2)
- 期末练习赛 构造数列 数学+模拟(兰福德数列)