From: Damyan Ivanov Date: Tue, 26 Nov 2019 22:00:39 +0000 (+0200) Subject: NT fragment: bind the view model to the activity X-Git-Tag: v0.11.0~13 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=b78d85afef509ea029aefe10e179f87a60108218;p=mobile-ledger.git 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 --- 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);