Created
June 1, 2018 16:45
-
-
Save SabagRonen/fdb5679738dae614346d6914d068bd99 to your computer and use it in GitHub Desktop.
What Problems Exist With Multi Activities blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SharedUiData | |
class FragmentInteractionViewModel : ViewModel() { | |
val interactionLiveData = MutableLiveData<SharedUiData>() | |
} | |
class FragmentA : Fragment() { | |
fun publishNextUiDataToNextScreen(sharedUiData: SharedUiData) { | |
val viewModel = ViewModelProviders.of(activity) | |
.get(FragmentInteractionViewModel::class.java) | |
viewModel.interactionLiveData.value = sharedUiData | |
} | |
} | |
class FragmentB : Fragment() { | |
override fun onViewCreated( | |
view: View?, | |
savedInstanceState: Bundle? | |
) { | |
super.onViewCreated(view, savedInstanceState) | |
val viewModel = ViewModelProviders.of(activity) | |
.get(FragmentInteractionViewModel::class.java) | |
viewModel.interactionLiveData.observe({lifecycle}) { | |
// do something with SharedUiData | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment