Friday 15 February 2013

android - How to persist fragment data after backstack transactions? -


I have an activity that has a 'slice' list, which will change itself by clicking on one of its items The 'content' piece when the user uses the back button, then it is again brought to the 'list' piece.
The problem is that this piece is in its default state, even if I try to continue with the data.

Facts

  1. Both the parts are set to the public static theragment newInstance (bundle arguments) , setArguments (args) and < Code> bundle args = pieces of both are at the same level, which are directly from the original code inside the FrameLayout (which are not nested pieces) >
  2. I do not want to call setRetainInstance , because my activity is a master / extension flow, which has 2 panel layouts on the large screen 7 "Pictures of bullets In 1 panel and There are 2 pan in the scenario. If I retain the 'list' piece example, then (i think) the screen rubbing things with rotation
  3. when users click on an item 'list 'Piece' is displayed through the 'content' slice FragmentTransaction # replace (int, slice, string) , but with a single ID but a different tag
  4. I override Done onSaveInstanceState (bundle) , but this frame is designed by not always is received, such as: "There are many situations where one piece may break mostly roughly (such as when placed on the back stack without showing the UI), but Its status will not survive until its own activity will actually need to save its position. "
  5. I'm using support libraries <5 bullets from above, I think low-end devices need to recover memory after a piece transaction , Which is not a valid option because the piece # onSaveInstanceState (bundle) on my test devices (Galaxy Nexus We and Nexus 7), the framework does not call that method.

    So, how can I retain some piece data? Always null from piece # onCreate , piece # to activated, and so on.

    Therefore, I can do a new one It does not matter if the back stack is restored from stacked launches.

    Note: Possible

    This does not seem right, but this is how I am ending:

      Public class MyActivity fragmentActivity {Private bundle mMainFragmentArgs; Public Zero savingManfragementstate (bundle argens) {mMainFr AgmentArgs = args;} Get the Public BundleSwedman FragmentState () {Return MAMFragmentArg; } // in the main piece:  
      The public square expands the main fragment fragment {@ Override public zero-zero activity ( Last Bundle Saved InstantStat) {Super.onCreate (Saved Instantstate); Bundle Args = ((MyActivity) getActivity ()). GetSavedMainFragmentState (); If (args! = Null) {// restore from backstack} and if (saved instenesttest! = Null) {// restore from saved instance state} else {/} arguments with arguments = getArguments () ; } // ...} // ... @ Override Public Zero Periodicview () {super.onDestroyView (); Bundle args = new bundle (); SaveInstance (args); (MyActivity) getActivity () SaveMainFragmentState (Args); } @overworked public watch on sightstation (bundle outstate) {super. On Asvenstastate (Outstate); SaveInstance (outState); } To save private zeros instance (bundle data) {// put data in bundle}}   

    This works!

    • If back from backstack, the piece uses the piece onDestroyView
    • the parameter saved in if it is outside of any other app / process / memory , Then restored to onSaveInstanceState
    • if the first time is created, then slice setArguments

      Uses the set parameter in which all events are covered, and the latest information is always kept.

      This is actually more complex, based on the interface ; the listener is registered with / code from onAttach / onDetach / is registered. But theories are the same.

No comments:

Post a Comment