android - How to change fragments within activity and save state -


i have activity have fragments dynamically added using method below.

fragmenttransaction transaction=getsupportfragmentmanager().begintransaction(); fragmenta fragmenta = new fragmenta(); transaction.add(r.id.fragment_container, fragmenta, "fragmenta");     transaction.addtobackstack("fragmenta");     transaction.commit(); 

fragmenta has textview. have navigation drawer on activity , want switch between fragments (for example fragmenta, fragmentb, , fragmentc) depending on item clicked in navigation drawer. how save state of fragments when changing fragment. i've implemented onsavedinstance(bundle outstate) , onactivitycreated(bundle savedinstancestate) savedinstancestate null. want able save fields of fragmenta when changing fragmentb , changing fragmenta fragmentb.

i cannot save state when pressing backstack. seems fields not being saved.

what correct ways this?

you can use shareprefrences save data in fragmenta , read when called again. additional advantage data saved in sharepreferences can read in other fragments if need be.

useful links on fragments;
- https://developer.android.com/training/basics/fragments/index.html

-http://www.vogella.com/tutorials/androidfragments/article.html


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -