Search code examples
androidpreferencessharedpreferences

Android, reading preferences


I am a noob learning android and building a simple game at the same time to face "real world problems" as I learn, the game is a simple maths game where two numbers are given and you have to choose the answer.

This is how I am doing it right now:
My little demo game starts (startscreen.java), click to go to the levels activity

in the levels activity (levels.java) I check the shared prefs for which level has passed (1 to 5) and display the highest, there is also a button to start the game.

Once the game is started (game.java), on 3 wrong answers I save the level to sharedpreferences if this level is higher than before and finish() the game to come back to the levels activity.

My problem is, when I come back to the levels activity now (from the game activity), it does not show the latest level that was just saved in the game activity :(
but if I restart the game or go to startscreen.java and come back it shows.

I can paste the code here if you need me to but I suspect you guys have already solved this :)
Thanks!
Ryan

EDIT: Added onResume, but it still does not work, my code: http://www.pastebin.com/wUUcpMDi


Solution

  • Override the onResume method of your levels activity to tell the UI to refresh with the new level information.