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 the information about the high score.
Starting the game goes to a second screen where the game starts and on the screen shows the current score and the score to be hit.
On that screen I was able to save the data with SharedPreferences
, I mean, on that screen is all ok, but I want to put the information of Highscore
from that second screen in the first, how to do?
On the Internet I thought to move from the first screen to Monday, but I did not find from the second screen to the first.
This may be the easiest solution but it is not the most optimized one. In view of that each time Activity calls the
onResume()
something will be searched to update the highscore and there will not necessarily be new data there. The best would be to start the second Activity using thestartActivityForResult()
and leave the preferences query only ononCreate()
.– Luiz
You’re right, there’s no reason not to
startActivityForResult()
. The solution would then be thus: http://answall.com/a/73628/357– Piovezan
Now, you can’t escape searching for the Highscore in the first Activity because the idea of the AP is to show it also before the game starts. Then the
startActivityForResult()
be more optimized is questionable.– Piovezan
He will have to search in the first Activity yes. But only in onCreate(). The difference in performance won’t be huge, but between quick exchanges to another App and back in the game, you don’t pay the price for another search on onResume(). Among other scenarios. So, yes, there is a gain, but it’s not something relatively large.
– Luiz
It is not great either because the amount of information accessed in the preferences is small. If it were for a large amount of data, the difference in quickly switching apps would be much more noticeable, for example.
– Luiz