0

My layout has a ViewPager with 3 Fragment. In the fragments, I've got a recyclerView populated from some arrayList and Maps. The output uses CardView with several buttons, and TextViews with dinamic data (buttons change the TextView values).

Everything working great, but now I'm implementing a Preference Activity. When I launch this Activity and then go back to my MainActivity, all the data changes are lost. Everything is showing its default value.

How can I handle or prevent this data loss?

Thank you!

EDIT: I came up with a solution, that at least for my purposes is fully working. Read this topic (I implemented that on my PreferenceActivity)..

Community
  • 1
  • 1
Raul Lopez
  • 68
  • 4

1 Answers1

0

Use sharedpreferences to store the data. And when the activity is reopened load the values from the sharedpreference. This way you can store the value till the app is not uninstalled. Another method is that instead of going to the mainActivity through startActivity(), you can do super.onBackPressed(). Another option is use sharedpreferences in the main activity. It checks whether there is a bundle which says getBoolean("restoreSelectedOptions", false). If this is true, then the values are restored and if false then fresh values have to be entered which then get stored into sharedpreferences.

suku
  • 10,507
  • 16
  • 75
  • 120