首页

android Aidl 例子源码下载

java

2020-7-29

数据传递的aidl

package com.example.testaidl;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
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.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;

public class MainActivity extends Activity implements OnClickListener {

	private Button btn_start,btn_stop;
	private TextView tv_sting;
	private ceshiAIDL aidl=null;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn_start = (Button)findViewById(R.id.btn_01);
        btn_stop = (Button)findViewById(R.id.btn_02);
        btn_stop.setEnabled(false);
        tv_sting = (TextView)findViewById(R.id.tv_01);
        btn_start.setOnClickListener(this);
        btn_stop.setOnClickListener(this);
    }

    private ServiceConnection serviceConnection = new ServiceConnection() {

		@Override
		public void onServiceConnected(ComponentName arg0, IBinder service) {
			Log.i(this.getClass().getName(), "连接服务成功!!");
			aidl = ceshiAIDL.Stub.asInterface(service);
			btn_stop.setEnabled(true);
		}

		@Override
		public void onServiceDisconnected(ComponentName arg0) {
			Log.i(this.getClass().getName(), "断开服务成功!!");
		}
    };

    
	@Override
	public void onClick(View v) {
         switch (v.getId()) {
		case R.id.btn_01:
			// 绑定AIDL服务 
			bindService(new Intent("com.example.testaidl.ceshiAIDL"), serviceConnection, Context.BIND_AUTO_CREATE);
			break;
         case R.id.btn_02:
			try {
				// 调用服务端的getValue方法
				tv_sting.setText(aidl.getValue());
			} catch (RemoteException e) {
				e.printStackTrace();
			}
			break;
		default:
			break;
		}		
	}
}
资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
TestAIDL/.classpath , 475
TestAIDL/.project , 844
TestAIDL/.settings/org.eclipse.core.resources.prefs , 91
TestAIDL/.settings/org.eclipse.jdt.core.prefs , 177
TestAIDL/AndroidManifest.xml , 1167
TestAIDL/bin/aidl/com/example/testaidl/ceshiAIDL.aidl , 80
TestAIDL/bin/AndroidManifest.xml , 1167
TestAIDL/bin/classes/com/example/testaidl/BuildConfig.class , 349
TestAIDL/bin/classes/com/example/testaidl/ceshiAIDL$Stub$Proxy.class , 1531
TestAIDL/bin/classes/com/example/testaidl/ceshiAIDL$Stub.class , 1810
TestAIDL/bin/classes/com/example/testaidl/ceshiAIDL.aidl , 80
TestAIDL/bin/classes/com/example/testaidl/ceshiAIDL.class , 325
TestAIDL/bin/classes/com/example/testaidl/MainActivity$1.class , 1635
TestAIDL/bin/classes/com/example/testaidl/MainActivity.class , 2331
TestAIDL/bin/classes/com/example/testaidl/MyService$InputString.class , 768
TestAIDL/bin/classes/com/example/testaidl/MyService.class , 643
TestAIDL/bin/classes/com/example/testaidl/R$attr.class , 346
TestAIDL/bin/classes/com/example/testaidl/R$dimen.class , 467
TestAIDL/bin/classes/com/example/testaidl/R$drawable.class , 413
TestAIDL/bin/classes/com/example/testaidl/R$id.class , 488
TestAIDL/bin/classes/com/example/testaidl/R$layout.class , 437
TestAIDL/bin/classes/com/example/testaidl/R$menu.class , 394
TestAIDL/bin/classes/com/example/testaidl/R$string.class , 478
TestAIDL/bin/classes/com/example/testaidl/R$style.class , 437
TestAIDL/bin/classes/com/example/testaidl/R.class , 693
TestAIDL/bin/classes.dex , 697492
TestAIDL/bin/dexedLibs/android-support-v4-c81e0667f48f100b3e7da8eb62913d1c.jar , 234431
TestAIDL/bin/jarlist.cache , 120
TestAIDL/bin/res/crunch/drawable-hdpi/ic_launcher.png , 5964
TestAIDL/bin/res/crunch/drawable-mdpi/ic_launcher.png , 3112
TestAIDL/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 9355
TestAIDL/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 17889
TestAIDL/bin/resources.ap_ , 41680
TestAIDL/bin/TestAIDL.apk , 282658
TestAIDL/gen/com/example/testaidl/BuildConfig.java , 162
TestAIDL/gen/com/example/testaidl/ceshiAIDL.java , 2506
TestAIDL/gen/com/example/testaidl/R.java , 2806
TestAIDL/ic_launcher-web.png , 51394
TestAIDL/libs/android-support-v4.jar , 627582
TestAIDL/proguard-project.txt , 781
TestAIDL/project.properties , 563
TestAIDL/res/drawable-hdpi/ic_launcher.png , 7658
TestAIDL/res/drawable-mdpi/ic_launcher.png , 3777
TestAIDL/res/drawable-xhdpi/ic_launcher.png , 12516
TestAIDL/res/drawable-xxhdpi/ic_launcher.png , 24777
TestAIDL/res/layout/fragment_main.xml , 706
TestAIDL/res/layout/main.xml , 1049
TestAIDL/res/menu/main.xml , 370
TestAIDL/res/values/dimens.xml , 220
TestAIDL/res/values/strings.xml , 225
TestAIDL/res/values/styles.xml , 697
TestAIDL/res/values-v11/styles.xml , 334
TestAIDL/res/values-v14/styles.xml , 391
TestAIDL/res/values-w820dp/dimens.xml , 381
TestAIDL/src/com/example/testaidl/ceshiAIDL.aidl , 80
TestAIDL/src/com/example/testaidl/MainActivity.java , 2185
TestAIDL/src/com/example/testaidl/MyService.java , 500
没有账号? 忘记密码?

社交账号快速登录