美文网首页
广播传值

广播传值

作者: 我叫杨毅 | 来源:发表于2017-12-23 13:09 被阅读20次

    传值页

    Intent intent=new Intent("content");//广播key

    intent.putExtra("content_tv",content);//内容key

    sendBroadcast(intent);

    finish();

    接收页

    // 1广播接收内部类

    class Receiver extends BroadcastReceiver{

    @Override

    public void on Receive(Context context,Intent intent) {

    String content=intent.getStringExtra("content_tv");

    Log.e(TAG,"onReceive: "+content );

    main_remark_et.setText(content);

    }

    }

    // 2广播接收

    Receiver receiver;

    // 3注册

    receiver=new Receiver();

    IntentFilter intentFilter=new IntentFilter("content");

    getContext().registerReceiver(receiver,intentFilter);

    // 4注销广播

    @Override

    public void on Destroy() {

    super.onDestroy();

    getContext().unregisterReceiver(receiver);

    }

    相关文章

      网友评论

          本文标题:广播传值

          本文链接:https://www.haomeiwen.com/subject/puxqgxtx.html