广播传值

2017-12-23  本文已影响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);

}

上一篇下一篇

猜你喜欢

热点阅读