简体   繁体   中英

Passing data on button click from five activities to one activity in android

This is for a game i am trying. First(1st activity) to Fith level(5th activity) have questions with multiple choice. The user is taken to the next level irrespective of what his answer is. At the end of the fifth level, he is told that 1) You have cleared all OR IF ONE OR MORE ARE WRONG 2) You have made a mistake.

ie he is notified of his result at the end of five levels.(he is not told which question is incorrect just that he has made a mistake)

Can somebody help me with the codes?

Here is the code to get you started with SharedPreferences

This is how you store in SharedPref, you can use it in each level to store the result:

public static final String GAME_PREFERENCES = "GamePrefs";
sharedPreferences settings = getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE);
sharedPreferences.Editor prefEditor = settings.edit();         
prefeditor.putBoolean("level1",YOUR_BOOL_VALUE);          
prefeditor.commit();

Similarly you use getBoolean to retrieve the values which you have stored (in the last activity)!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM