标签:android 按返回键 通过广播刷新数据 广播注册销毁发送
案例:有两个Activity,第一个Activity中有一个按钮,这个按钮的Text是pca,点击之后跳到定外的Activity,在定外一个Activity中发送广播,改变第一个Activity中按钮Text的值,变成chy。下面请看代码:
1.自定义广播接收者
private class MBroadcastReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { userName = "chy"; bt1.setText(userName); } }
广播的Action
public static final String USER_BROD_ACTION = "user.broadcast.action";注册广播:
MBroadcastReceiver receiver; receiver = new MBroadcastReceiver(); IntentFilter filter = new IntentFilter(Constants.USER_BROD_ACTION); registerReceiver(receiver, filter);
@Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); unregisterReceiver(receiver); }
Intent intent = new Intent(Constants.USER_BROD_ACTION); sendBroadcast(intent);
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:android 按返回键 通过广播刷新数据 广播注册销毁发送
原文地址:http://blog.csdn.net/pcaxb/article/details/47751947