From b78d85afef509ea029aefe10e179f87a60108218 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 27 Nov 2019 00:00:39 +0200 Subject: [PATCH] NT fragment: bind the view model to the activity the fragment can be re-created when navigating to the save progress fragment. when it is re-created the view model instance is re-created too, losing the unsaved transaction --- .../ktnx/mobileledger/ui/activity/NewTransactionFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index 7101f44f..5b197b00 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -86,13 +86,13 @@ public class NewTransactionFragment extends Fragment { @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - Activity activity = getActivity(); + FragmentActivity activity = getActivity(); if (activity == null) throw new RSInvalidStateException( "getActivity() returned null within onActivityCreated()"); list = activity.findViewById(R.id.new_transaction_accounts); - viewModel = ViewModelProviders.of(this) + viewModel = ViewModelProviders.of(activity) .get(NewTransactionModel.class); mProfile = Data.profile.getValue(); listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile); -- 2.39.5