Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class SharedViewModel extends ViewModel {}
public class MasterFragment extends Fragment {
    private SharedViewModel model;
    public void onCreate(Bundle savedInstanceState) {
        model = ViewModelProviders.of(getActivity())
.get(SharedViewModel.class); //<- 共通のviewmodel
    }
}
public class DetailFragment extends LifecycleFragment {
    public void onCreate(Bundle savedInstanceState) {
        SharedViewModel model = ViewModelProviders.of(getActivity())
.get(SharedViewModel.class); //<- 共通のviewmodel
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment