/** * Sub-class may override this to restore more elements. * * @param savedInstanceState */ protected void restore(Bundle savedInstanceState) { try { if (savedInstanceState != null) { int visibility = savedInstanceState.getInt("playerVisibility", View.GONE); View container = findViewById(R.id.container_player); if (container != null) { container.setVisibility(visibility == View.VISIBLE ? View.VISIBLE : View.GONE); } if (playerFragment == null) { FragmentManager fm = getSupportFragmentManager(); playerFragment = (PlayerFragment) fm.getFragment(savedInstanceState, "player"); if (playerFragment != null && container != null) { FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.container_player, playerFragment, "player"); ft.commit(); } else { logger.warn("PlayerFragement needs to be restored, no container found!"); restore(playerFragment); } } } } catch (Exception ex) { logger.error(ex); } }
@Override public void restoreState(Parcelable state, ClassLoader loader) { if (state != null) { Bundle bundle = (Bundle) state; bundle.setClassLoader(loader); mItemIds = bundle.getLongArray("itemids"); if (mItemIds == null) { mItemIds = new long[] {}; } Parcelable[] fss = bundle.getParcelableArray("states"); mSavedState.clear(); mFragments.clear(); if (fss != null) { for (int i = 0; i < fss.length; i++) { mSavedState.add((Fragment.SavedState) fss[i]); } } Iterable<String> keys = bundle.keySet(); for (String key : keys) { if (key.startsWith("f")) { int index = Integer.parseInt(key.substring(1)); try { Fragment f = mFragmentManager.getFragment(bundle, key); if (f != null) { while (mFragments.size() <= index) { mFragments.add(null); } f.setMenuVisibility(false); mFragments.set(index, f); } else { Log.w(TAG, "Bad fragment at key " + key); } } catch (Exception ex) { Log.w(TAG, "Cannot restore fragment " + key, ex); } } } checkForIdChanges(); } }