Update activity from a second activity
I need to update the score in one activity when an action is used in another activity.
In class 1 activity 1 - I have a score textview and this shows the score. The user then presses answer and this takes the user to another activity where they choose an answer from radio buttons.
In class 2 activity 2 - The user chooses an answer and the score 开发者_开发百科in activity 1 gets updated if correct.
Is this possible?
Thanks.
if your using intents to launch you activities then you might want to look into passing the values as extra
Edit
I found a good article about extra (get and set extra) I found a good article about extra (get and set extra) Section 3 should be what your looking for
I'd create a class called GameController or something to that effect, and both Activities would interact with a single instance of this class.
Or if you want to keep it simple, open Activity2 with startActivityForResult and return the answer back to Activity1. That way Activity1 has all the logic for keeping score as well as displaying it.
Using multiple activities for something like this seems like overkill. Why not just have two views in the same activity and just flip between them?
You could use the Transition3d sample from the ApiDemos as a starting point.
精彩评论