zoukankan      html  css  js  c++  java
  • AIDL

    ServiceConnection conn = new ServiceConnection() {
    	
    	@Override
    	public void onServiceDisconnected(ComponentName name) {
    		// TODO Auto-generated method stub
    		
    	}
    	
    	@Override
    	public void onServiceConnected(ComponentName name, IBinder service) {
    		appleService = IApple.Stub.asInterface(service);
    		
    	}
    };
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		color = (EditText) findViewById(R.id.color);
    		weight = (EditText) findViewById(R.id.weight);
    		get = (Button) findViewById(R.id.get);
    		Intent intent = new Intent();
    		intent.setAction("AIDLSERVICETEST");
    		//绑定到远程服务上
    		bindService(intent, conn, Service.BIND_AUTO_CREATE);
    		get.setOnClickListener(new OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				try {
    					color.setText(appleService.getColor());
    					weight.setText(appleService.getWeight()+"");
    				} catch (RemoteException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    	@Override
    	protected void onDestroy() {
    		// TODO Auto-generated method stub
    		unbindService(conn);
    		super.onDestroy();
    	}
    
    }

  • 相关阅读:
    关于类型转换构造函数的疑惑点
    类模板与静态 成员变量
    模板与友元
    类模板与派生
    类模板
    函数模板
    泛型程序设计基本概念
    3、成员函数
    条款 06:若不想使用编译器自动生成的函数,就该明确拒绝
    PHP操作redis
  • 原文地址:https://www.cnblogs.com/allencoder/p/3643916.html
Copyright © 2011-2022 走看看