R
R
RomanoO2012-04-10 22:55:58
Android
RomanoO, 2012-04-10 22:55:58

How to save fragment state when FragmentTransaction.detach() is called?

Good evening, Habr!
Help, who can ...
Wrote a tabbed application using this manual . I ran into a problem that when tabs are switched, onSavedInstanseState of the fragment on the current tab is not called, and when switching back, all calls go in order, and, of course, nothing is restored from savedInstanceState. How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RomanoO, 2012-04-11
@RomanoO

Everything is easier than expected:
LinkedList savedDevicesNames = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
if (D) { Log.d(TAG, "onActivityCreated"); }
super.onActivityCreated(savedInstanceState);
if (savedDevicesNames != null) {
for (String deviceNameAddr : savedDevicesNames) {
adapter.add(deviceNameAddr);
}
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
savedDevicesNames = new LinkedList();
for (int i = 0; i < adapter.getCount(); i++) {
savedDevicesNames.add(adapter.getItem(i));
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question