关于android中使用bindservice进行传值的问题?

移动开发 码拜 9年前 (2015-04-25) 1664次浏览 0个评论

在一个activity中点击注册按钮后向service发送从activity中获得的帐号密码。
但是在service中检查发现账户名重复需要重新输入帐户名,但是修改帐户名后再次点击注册按钮,在service中调用onrebind后获得的还是原来的帐户名。

public IBinder onBind(Intent intent) {
Log.i(“MyService”, “onBind”);
Bundle bl = intent.getExtras();
Name = bl.getString(“NAME”);
Password = bl.getString(“PASSWORD”);
return mBinder;
}

public boolean onUnbind(Intent intent){
Log.i(“MyService”, “onUnbind”);
return true;
}

public void onRebind(Intent intent){
Log.i(“MyService”, “onRebind”);
Bundle bl = intent.getExtras();
String tempName = bl.getString(“NAME”);
Password = bl.getString(“PASSWORD”);
Log.i(“MyService”, tempName);
super.onRebind(intent);

关于android中使用bindservice进行传值的问题?
40分
可以先解除绑定咯
关于android中使用bindservice进行传值的问题?
可是我已经解除绑定了,这是activity中的部分代码:
public void sign_up_confirm(View view){
        edit_name = name.getText().toString();
        edit_password = password.getText().toString();
        if(edit_name.equals(“”) || edit_password.equals(“”)){
            return;
        }
        Bundle bl = new Bundle();
        bl.putString(“NAME”, edit_name);
        bl.putString(“PASSWORD”, edit_password);
        Log.i(“MyActivity”, edit_name);
        Intent bindIntent = new Intent();
        bindIntent.setClass(this,MyService.class);
        bindIntent.putExtras(bl);
        bindService(bindIntent, connection, BIND_AUTO_CREATE);
        UNBIND = true;
    }
    public class MyReceiver extends BroadcastReceiver{
        public void onReceive(Context context, Intent intent){
            Bundle bundle = intent.getExtras();
            String Warning = bundle.getString(“warning”);
            if (Warning.equals(“Sign up faile”)){
                UNBIND = false;
                unbindService(connection);
            }
            else if (Warning.equals(“Sign up success”))
            {
                UNBIND = true;
            }
        }
    }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于android中使用bindservice进行传值的问题?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!