D
D
Denis2016-09-18 22:16:34
Android
Denis, 2016-09-18 22:16:34

Why is onSaveInstanceState not called when the fragment is changed?

This is how I change the snippet

ProjectPage frag1;//ссылка на фрагмент
                FragmentTransaction fTrans;//ссылка на транзакции
                frag1 = new ProjectPage();//создание объекта фрагмента
                fTrans = getActivity().getSupportFragmentManager().beginTransaction();
                Bundle args = new Bundle();
                save_state_bundle(args);
                frag1.setArguments(args);
                fTrans.replace(R.id.main_layout, frag1);
                fTrans.addToBackStack(null);
                fTrans.commit();

But this does not call the onSaveInstanceState method. However, when returning to the fragment, filled EditTexts retain their state.
Also, the life cycle of the fragment comes to onDestroyView. But does not call onDestroy and onDetach.
And on return, onCreateView, onStart, onResume are called.
As I understand it, the fragment itself is not destroyed, but only its view is destroyed, but then why is its state partially restored if the onSaveInstanceState method was not called?
And yet, as I understand from the documentation, if there is not enough memory, the fragment itself can be deleted, even without calling onDestroy and onDetach, where then to store the state of the fragment?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question