Before 2022/Android

Activity에서 Fragment로 데이터 전송

Eljoe 2019. 1. 28. 12:58
Activity
Bundle bundle = new Bundle(1);
bundle.putInt("state", 1);
yourFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().add(R.id.fl_layout, yourFragment).commit();
Fragment
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 
                         @Nullable Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.fragment_verifying, container, false);
	unbinder = ButterKnife.bind(this, view);
	
	int state = 0;
	
	if (getArguments() != null){
		state = getArguments().getInt("state");
	} 
	
	return view;
}