当前位置: 首页 > news >正文

帮传销组织做网站网站建设平台方案

帮传销组织做网站,网站建设平台方案,济源市工程建设监理所网站,网站推广营销方法一、AIDL Service简介 Android系统中#xff0c;各个应用都运行在自己的进程中#xff0c;进程之间一般无法直接进行通信#xff0c;为了实现进程通信#xff0c;Android提供了AIDL Service#xff1b; 二、与本地Service不同 本地Service#xff1a;直接把IBinder对象… 一、AIDL Service简介 Android系统中各个应用都运行在自己的进程中进程之间一般无法直接进行通信为了实现进程通信Android提供了AIDL Service 二、与本地Service不同  本地Service直接把IBinder对象本身传递给客户端的ServiceConnection的onServiceConnected方法的第二个参数 远程Service只将IBinder对象的代理传给客户端的ServiceConnection的onServiceConnected方法的第二个参数 三、AIDL文件Android需要AIDLAndroid Interface Definition Language来定义远程接口这种接口定义语言并不是一种真正的变成语言只是定义两个进程之间的通信接口与Java接口相似但是存在如下几点差异AIDL定义接口的源代码必须以.aidl结尾  AIDL用到的数据类型除了基本类型、String、List、Map、CharSequence之外其它类型全部都需要导包即使它们在同一个包中也需要导包四、例子1. 创建AIDL文件,定义好的AIDL文件后ADT工具会自动在gen目录下生成一个AIDL.java接口该类内部包含一个Stub内部类实现了IBinderAIDL里面的接口这个Stub类会作为远程Service回调类 IMyService.aidl package com.juno.serviceaidltest; import com.juno.serviceaidltest.Product; interface IMyService { String getValue(); Map getMap(in String country, in Product product); Product getProduct(); } Product.aidl parcelable Product; Product.java package com.juno.serviceaidltest; import android.os.Parcel; import android.os.Parcelable; public class Product implements Parcelable { private int id; private String name; private float price; public static final Parcelable.CreatorProduct CREATOR new Parcelable.CreatorProduct() { public Product createFromParcel(Parcel in) { return new Product(in); } public Product[] newArray(int size) { return new Product[size]; } }; public Product() { } private Product(Parcel in) { readFromParcel(in); } Override public int describeContents() { return 0; } public void readFromParcel(Parcel in) { id in.readInt(); name in.readString(); price in.readFloat(); } Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(name); dest.writeFloat(price); } public int getId() { return id; } public void setId(int id) { this.id id; } public String getName() { return name; } public void setName(String name) { this.name name; } public float getPrice() { return price; } public void setPrice(float price) { this.price price; } } 2. 将接口暴露给客户端MyService.java package com.juno.serviceaidltest; import java.util.HashMap; import java.util.Map; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.RemoteException; public class MyService extends Service { /** * 继承Stub,也就是实现了IMyService接口并实现了IBinder接口 */ public class MyServiceImpl extends IMyService.Stub { Override public String getValue() throws RemoteException { return Test Value; } Override public MapString, Object getMap(String country, Product product) throws RemoteException { MapString, Object map new HashMapString, Object(); map.put(country, country); map.put(id, product.getId()); map.put(name, product.getName()); map.put(price, product.getPrice()); map.put(product, product); return map; } Override public Product getProduct() throws RemoteException { Product product new Product(); product.setId(1234); product.setName(汽车); product.setPrice(31000); return product; } } Override public IBinder onBind(Intent intent) { /** * 返回MyServiceImpl对象在绑定本地Service情况下该MyServiceImpl会直接传给客户端的ServiceConnected对象的ServiceConnected()方法的第二个参数在绑定远程Service的情况下只将MyServiceImpl对象的代理传给客户端的ServiceConnected对象的ServiceConnected()方法的第二个参数 */ return new MyServiceImpl(); } } 3.  在AndroidManifext.xml文件中配置该Service:service android:name.MyService intent-filter action android:namecom.juno.serviceaidltest.IService / /intent-filter /service4. 在Activity里访问 AIDLService,如果不在同一个App下面访问需要将Service端的AIDL文件复制到客户端中并在相同的包名下MainActivity.java package com.juno.serviceanotheraidltest; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.juno.serviceaidltest.IMyService; public class MainActivity extends Activity implements View.OnClickListener { private final static String ACTION com.juno.serviceaidltest.IService; private IMyService myService null; private Button mBtnInvokeAIDLService; private Button mBtnBindAIDLService; private TextView mTextView; private ServiceConnection mServiceConnection new ServiceConnection() { Override public void onServiceConnected(ComponentName name, IBinder service) { //获取远程Service的onBinder方法返回的对象代理 myService IMyService.Stub.asInterface(service); mBtnInvokeAIDLService.setEnabled(true); try { Log.v(juno, myService.getValue()); } catch (RemoteException e) { e.printStackTrace(); } } Override public void onServiceDisconnected(ComponentName name) { myService null; } }; Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { mBtnInvokeAIDLService (Button) findViewById(R.id.btnInvokeAIDLService); mBtnBindAIDLService (Button) findViewById(R.id.btnBindAIDLService); mBtnInvokeAIDLService.setEnabled(false); mTextView (TextView) findViewById(R.id.textView1); mBtnInvokeAIDLService.setOnClickListener(this); mBtnBindAIDLService.setOnClickListener(this); } Override public void onClick(View view) { switch (view.getId()) { case R.id.btnBindAIDLService: //创建所需要绑定的Service的Intent绑定远程的服务 bindService(new Intent(ACTION), mServiceConnection, Context.BIND_AUTO_CREATE); break; case R.id.btnInvokeAIDLService: try { String s myService.getValue(); s Product.id myService.getProduct().getId() \n; s Product.name myService.getProduct().getName() \n; s Product.price myService.getProduct().getPrice() \n; s myService.getMap(China, myService.getProduct()).toString(); mTextView.setText(myService.asBinder().isBinderAlive() s); } catch (Exception e) { } break; } } Override protected void onDestroy() { super.onDestroy(); if (myService ! null) { //解除绑定 unbindService(mServiceConnection); } } } 布局文件activity_main.xml RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:toolshttp://schemas.android.com/tools android:layout_widthmatch_parent android:layout_heightmatch_parent android:paddingBottomdimen/activity_vertical_margin android:paddingLeftdimen/activity_horizontal_margin android:paddingRightdimen/activity_horizontal_margin android:paddingTopdimen/activity_vertical_margin tools:context.MainActivity TextView android:idid/textView1 android:layout_widthwrap_content android:layout_heightwrap_content android:textstring/hello_world / Button android:idid/btnBindAIDLService android:layout_widthwrap_content android:layout_heightwrap_content android:layout_belowid/textView1 android:textbtnBindAIDLService / Button android:idid/btnInvokeAIDLService android:layout_widthwrap_content android:layout_heightwrap_content android:layout_belowid/btnBindAIDLService android:textbtnInvokeAIDLService / /RelativeLayout
http://www.zqtcl.cn/news/869568/

相关文章:

  • 甘肃省酒泉市做网站公司wordpress标签云代码
  • 淘宝客做网站备注怎么写的用手机做网站视频
  • 深圳专业网站建设制作价格低品牌网站建设网站
  • 织梦体育网站模板临沂建站程序
  • 重庆网站设计最佳科技好听的网络公司名字
  • 如何在人力资源网站做合同续签贵阳网站建设搜王道下拉
  • 多个域名的网站北京注册公司流程
  • 网站建站对象定制网站系统
  • 阳光家园广州网站网站公司怎么做的好
  • wordpress网站音乐放不全阳山做网站
  • 橙色企业网站源码网站下载软件
  • 满足客户的分销管理系统seo搜索引擎优化技术教程
  • 链接网站制作住房建设部官方网站专家注册
  • 北京保障性住房建设投资中心网站以网络营销为主题的论文
  • 数字火币交易网站开发网站建设设计图图片
  • 惠民建设局网站东莞公司建设网站
  • 网站建设与维护教学课件煤炭网站建设规划书
  • 北京建设网站有哪些公司黄陌陌网站怎么做
  • 视频网页制作教程网站优化防范
  • 做优化网站注意什么开发者模式开着好不好
  • 网站顾客评价网站中怎么做网站统计
  • 网站建设安全措施表白网站是怎么做的
  • 一个服务器可以做几个网站百度北京公司地址全部
  • 武侯区网站建设哪里好点个人社保缴费比例是多少
  • 创建属于自己的网站定制应用软件有哪些
  • 网站建设类岗位建设工程施工合同示范文本2023最新版
  • 建站设计公司wordpress 跨域 cros
  • 做网站的公司哪好工程设计东莞网站建设技术支持
  • 虹口网站开发开发公司设计管理部绩效考核
  • 网站改版升级通知国外服务器公司有哪些