How to save the state of an Fragment in android?
NickName:Ali Ask DateTime:2014-07-23T20:29:55

How to save the state of an Fragment in android?

I only have a switch toggle on my fragment. What is the app doing now: The user opens the app and selects "Laptop" over the navigation drawer and then he sees a switch (it is a "slider" which you can move to on or off...hope you understand what I mean). The user sets switch to ON then closes the app and reopens it and the switch is off...but it shouldn't be off...it should be on, like the user sets it How can I do that? The switch should save its state, how the user selects it. Do I need mysql or something?

(By the way, I am using Android Studio)

I hope you understand what I mean

Thanks

Copyright Notice:Content Author:「Ali」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24910518/how-to-save-the-state-of-an-fragment-in-android

Answers
user2670032 2014-07-23T12:40:20

try using shared preferences to save application data, Application can save data in share preferences when application start again it can load data from shared preferences again ... hope it help :)",


More about “How to save the state of an Fragment in android?” related questions

How to save state of fragment in android?

i am using four fragments in one activity Four buttons at bottom are used to switch between fragments I have search button of action bar But when i am clicking on search button keyboard appears and...

Show Detail

How to save the state of an Fragment in android?

I only have a switch toggle on my fragment. What is the app doing now: The user opens the app and selects "Laptop" over the navigation drawer and then he sees a switch (it is a "slider" which you can

Show Detail

How to save fragment state

I have SettingActivity. It contains SettingFragment (with ListPreference) and another AudioSamplingSeekBarFragment(with my custom preference in it). When i choose some item in ListPreference, i rec...

Show Detail

How to save to state of fragment on replace

I hope for your help in understanding how to implement my task. I have MainActivity in which I show one or the other fragment (for simplicity let's call them FragmentA and FragmentB). Just outsid...

Show Detail

Fragment save view state

I have some Fragment with this structure: <RelativeLayout android:id="@+id/control_panel" android:visibility="gone"> <RelativeLayout androi

Show Detail

How to save the state of service in android

My android service is uploading file on server and it is a sticky service and 90percent is already gets uploaded and in between android system killed that service how will I able to restore the upl...

Show Detail

How to save state in fragment

I have 4 button to replace fragment in activity [fragment A , fragment B , fragment C , fragment D] and then I replace fragment A to activity and I change value in fragment A after that I replace

Show Detail

how to save current state of fragment

in my MainActivity, I have a bottom menu and a FrameLayout. each bottom loads specific fragment using code bellow: bottomNavigation.setOnClickMenuListener { when (it.id) { 1 ...

Show Detail

Cannot save fragment state during rotation

I have several fragments in activity, changed by bottombar. I tried to implement fragment state handling by using Once for all, how to correctly save instance state of Fragments in back stack? The

Show Detail

Android : Save fragment state and restore the view values

Hi iam trying to save the state of the fragment when one fragment is replaced with other fragment. Consider in my Activity i have a fragmentA with textview-1 and textview-2. when i click on the te...

Show Detail