android message 传递bundle

android message 传递bundle,第1张

android message 传递bundle

发送端:

 Message msg = new Message();
                Bundle bundle = new Bundle();

                Player player = new Player(UserName,UserPass);
                bundle.putParcelable("person",player);

                msg.setData(bundle);
                msg.what=LoginMainPage.SIGN_SUCCESS_BACK;
                LoginMainPage.mhandler.sendMessage(msg);
                finish();

接受端:

    public static Player callback_player;
    public static Handler mhandler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            if (SIGN_SUCCESS_BACK == msg.what) {
                callback_player = msg.getData().getParcelable("person");
            }
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("onResume!");
        if(callback_player !=null){
        Toast.makeText(this,"Handler传递数据:"+callback_player.user_name,Toast.LENGTH_LONG).show();
    }
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5717944.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存