0

For example:

I have a game of clicking in objects, so there are variables like

openDoor = true;
openChest = false;

When user close window and restart the game I have to return him/her with his/her progress.

What should I do?

Study Text file? Save on Database?

Put some code in somewhere to save the status?

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
  • It's a simple question but I've started Android in 2018 and need some orientations. Thank you. – Rogeres Oliveira Feb 19 '18 at 13:25
  • use sharedpreferences for saving – EL TEGANI MOHAMED HAMAD GABIR Feb 19 '18 at 13:25
  • SharedPreferences – Manohar Feb 19 '18 at 13:26
  • see this https://stackoverflow.com/a/3624358/9130109 – EL TEGANI MOHAMED HAMAD GABIR Feb 19 '18 at 13:27
  • It depends on the data you want to store. If the data you want to store can be treated as one class objects. Then I would prefer serialize and deserailize object and write in to internal mem cache. So that u can read the same object when user returns to app. It will be helpful if you have more than 5 property to save. If u have less than 5 I would prefer shared preference. – lib4backer Feb 19 '18 at 13:29
  • I'm already reading: https://developer.android.com/guide/topics/data/data-storage.html#pref – Rogeres Oliveira Feb 19 '18 at 13:47
  • Guys, I am testing saving data. It's okay but it seems sharedPreferences only Works on onResume(). I tried to put it on onDestroy() and it doesn't work. I close the app to test but it doesn't work. – Rogeres Oliveira Feb 20 '18 at 00:21
  • User has to choose two objects among three but I want it to be possible when he/she come back onResume(). But if I save data onResume it's not possible because when they come back the objects have desappeared. I'd like to save shareed preferences only when the activity was closed. – Rogeres Oliveira Feb 20 '18 at 00:31

1 Answers1

1

If the data you need to store is quite small or less than I would recommend you to use SharedPreference. It is the best practice to use this when you need to store the user's status. SharedPreference are quite private so your data won't be accessible to other apps. You can go through this.

Pranay Soni
  • 403
  • 3
  • 12