How to transfer some data to another Fragment?

前端 未结 10 2024
说谎
说谎 2020-11-22 11:41

How to transfer some data to another Fragment likewise it was done with extras for intents?

10条回答
  •  故里飘歌
    2020-11-22 12:24

    If you are using graph for navigation between fragments you can do this: From fragment A:

        Bundle bundle = new Bundle();
        bundle.putSerializable(KEY, yourObject);
        Navigation.findNavController(view).navigate(R.id.fragment, bundle);
    

    To fragment B:

        Bundle bundle = getArguments();
        object = (Object) bundle.getSerializable(KEY);
    

    Of course your object must implement Serializable

提交回复
热议问题