My app is a basic golf counter that is mainly an array of “hole” objects that contains 2 integers; hole number and the stroke number.
I am trying to save the information to the phone as a string when the app is killed and then read it back in and use String.split() and Integer.parse() to write the information back into the array.
I use OnPause() and OnResume() and I have been testing my app by pressing the back arrow button to see if it is saving. But I cant seem to get it to work.
Am I right to use OnPause() and OnResume()?
if you wan the values to be saved permanently, then you need to use SharedPreferences like this:
if you don’t include the
commit()then nothing happens. also you can (and i would) use method chaining for theSharedPreferences, i just thought i should keep it simple.it is just as easy to leave them as int (or int[] i wasnt entirely clear which you were going for) instead of dealing with all that splitting and parseing. now if you are trying to add them so that everytime you quit, your hole and strike are added to an evergrowing array, thats a little more complex and i can help you with that too if thats the case.