P
P
Pavel Isakov2014-07-01 20:24:06
Android
Pavel Isakov, 2014-07-01 20:24:06

How to make Fragment#onSaveInstanceState be called when switching fragments in NavigationDrawer?

I generated a project in AndroidStudio with NavigationDrawer.
How to follow so that when switching between fragments, the onSaveInstanceState method is called in the current fragment. So that when switching back, restore the state of the fragment.
Fragments switch like this:

public void onNavigationDrawerItemSelected(int position) {
        // update the main content by replacing fragments
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
                .commit();
    }

The project itself: GitHub

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat S, 2014-07-02
@aratj

most probably not.
onSaveInstanceState will be called when the activity is crashed by the system
or when the configuration changes.
in principle, before replace, you can
take away its data in the bandle from the fragment, and then transfer it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question