基本信息
源码名称:android AIDL 最简demo
源码大小:0.05M
文件格式:.rar
开发语言:Java
更新时间:2015-09-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.test; import com.aidl.forService; 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.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private static final String loveConfession = "You complete me."; protected static final String _TAG = "TAG"; com.aidl.forService ms; //MySevice ms; Button bt1,bt2; private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d("TAG", "onServiceConnected"); ms = forService.Stub.asInterface(service); } public void onServiceDisconnected(ComponentName className) { Log.d("TAG", "onServiceDisConnected"); } }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bt1 = (Button) this.findViewById(R.id.Button01); bt2 = (Button) this.findViewById(R.id.Button02); bt1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub Intent it = new Intent(MainActivity.this,MySevice.class); bindService(it, mConnection, Context.BIND_AUTO_CREATE); startService(it); } }); bt2.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub try { ms.Speak(loveConfession); Log.d(_TAG, "bt2"); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } }