Service (aidl远程服务)
2016-01-28 16:35
399 查看
Service (aidl远程服务)
game工程调用alpay工程的pay服务alpay工程
支付的服务
public class PayService extends Service { @Override public IBinder onBind(Intent intent) { AiPay aiPay = new AiPay(); return aiPay; } class AiPay extends Stub{ @Override public void pay() throws RemoteException { PayService.this.pay(); } } public void pay(){ System.out.println("检测支付环境是否安全"); System.out.println("加密账号密码"); System.out.println("建立连接"); System.out.println("上传数据"); System.out.println("完成支付"); } }
aidl (Android Interface Definition Language)
去掉public声明package com.example.alpay; interface PayInterface { void pay(); }
AndroidManifest.xml配置
<service android:name="com.example.alpay.PayService"> <intent-filter > <action android:name="com.example.alpay"/> </intent-filter> </service>
game工程
aidl文件复制到同名包下
在game工程中调用alpay工程的pay方法
// 隐式启动服务 Intent intent = new Intent(); intent.setAction("com.example.alpay"); // 绑定服务, 内部类实现ServiceConnection接口 bindService(intent, new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { asInterface = Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub } }, BIND_AUTO_CREATE); findViewById(R.id.btn_pay).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { asInterface.pay(); } catch (RemoteException e) { e.printStackTrace(); } } });
相关文章推荐
- LTP 源码分析-- testcases/kernel/containers
- FATAL: DTM initialization: failure during startup recovery, retry failed, check segment status (cdb
- hdu4251The Famous ICPC Team Again【划分树入门题】
- StringUtils.containsOnly使用说明
- How to correctly read data when using epoll_wait
- C++——STL所有算法介绍 http://blog.csdn.net/shinehoo/article/details/5736155
- 关于baidu_tempalate 的使用
- HDFS-RAID
- 通用的contain函数
- Page Rendering - Main Frame and Impl Frame
- 面对谷歌围棋AI,人类最后的智力骄傲即将崩塌
- VS中更改栈和堆空间的大小http://blog.csdn.net/allenjiao/article/details/8516049
- Suricata源码阅读笔记:main()
- windows下绑定线程(进程)到指定的CPU核心 http://blog.csdn.net/beyond_cn/article/details/15813361
- linker command failed with exit code 1 (use -v to see invocation)解决办法
- 安装apk报错INSTALL_FAILED_UPDATE_INCOMPATIBLE的解决方法
- 我的博客是http://blog.csdn.net/baidu_33742532。
- Azure:Manage anonymous read access to containers and blobs
- SharePoint 2013 Error - File names can't contain the following characters: & " ? < > # {} % ~ / \.
- 色子作画 Dice Mosaic