当一个类, 继承了Fragment 时, 由于是为了实现屏幕可以左右滑动效果, 当发布一个内容时, 通过广播来实现刷新列表.
那么广播的注册只能在这个方法里面写
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
//注册广播,
IntentFilter filter = new IntentFilter();
filter.addAction("APP_ASK");
activity.registerReceiver(broadcastReceiver, filter);
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getStringExtra("action");
if ("add".equals(action)) {
}
}
};
不能在onCreate 里面注册