I want to pass a value from an activity to fragment via EventBus
. I can pass the value and read with @Subscribe
method. But I can't pass the value to a variable at the beginning of onCreateView - setupGridView(mUser). I want to add the value setupGridView
as a parameter. Is it possible to get EventBus data at the very beginning of onCreateView()
?
private User mUser;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile_pages, container, false);
setupGridView(mUser);// mUser is null here
}
@Subscribe
public void mSetUser(User user){
mUser = user;
Log.d(TAG, "mUser: " + user.toString());//I can see data here
}
@Override
public void onAttach(Context context) {
EventBus.getDefault().register(this);
super.onAttach(context);
}
@Override
public void onDetach() {
super.onDetach();
EventBus.getDefault().unregister(this);
}