Pass data between Android Activity [duplicate]

0

I'm new to programming for android, and I just made my first app, but I'm having a problem, which is:

My game has the start menu with the button to start the game and information about the high score.

Starting the game goes to a second screen where the game starts and the screen shows the current score and the score to be beat.

On this screen I was able to save the data with SharedPreferences , that is, on this screen everything is ok, but I want to put the information of Highscore of this second screen in the first one, how to do it?

On the internet, I figured to go from the first screen to the second, but I did not find it from the second screen to the first one.

    
asked by anonymous 28.02.2016 / 01:33

1 answer

1

In your case I would recommend that in the onResume() method of the first screen you search the data stored in Shared Preferences and display them. That way, when you are on the second screen and press the "back" button to return to the first screen, the onResume() method will be called and Highscore will be updated.

On the first screen you can even leave the Highscore display only on onResume() , without having to display it in onCreate() . The activity lifecycle will make things work correctly, since after onCreate() onResume() is automatically called.

    
28.02.2016 / 01:53