android远程服务

客户端和被调用实现之间是通过代理模式实现的,代理类和被代理类实现同一个接口Ibinder接口。

1、服务端实现:
在android创建一个文件LoginService 继承 Service

public class QQLoginService extends Service {

    class MyIBinder extends Binder implements QQLongsertfase{
        @Override
        public boolean login(String number, String pwd) {
               if("subijun".equals(number)&&"123".equals(pwd)){
              return true;
            }
            return false;
        }
//        public boolean login(String number,String pwd){
//            if("subijun".equals(number)&&"123".equals(pwd)){
//              return true;
//            }
//            return false;
//        }
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new MyIBinder();
    }
}

实例化一个接口 
ServiceConnection 进行连接服务。在onBind方法里面返回我们定
义的接口实例

ServiceConnection connection=new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(“test”,”绑定成功”);
// myBinde = (QQLoginService.MyIBinder) service;
qqLongsertfase = (QQLongsertfase)service;
}

    @Override
    public void onServiceDisconnected(ComponentName name) {

    }
};
在Manifest文件里面进行注册


2、客户端实现:
客户端的代码  
两个文本输入框、一个按钮
点击按钮调用远程服务端的方法执行加法操作,然后在文本控件中显示。
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="subijun"
    android:id="@+id/EdiTtext_main_number"
    />
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="123"
    android:id="@+id/EdiTtext_main_pwd"
    />
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="登录"
    android:onClick="login"
    />

“`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值