Created
January 7, 2013 12:05
-
-
Save ifinoi/4474515 to your computer and use it in GitHub Desktop.
Implementation of LastBreath in game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyGame extends Activity implements ExceptionCallback { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//Init BugSense | |
BugSenseHandler.initAndStartSession(this, APIKEY); | |
//Set the exception callback | |
BugSenseHandler.setExceptionCallback(this); | |
//Check shared preferences if game crashed | |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
boolean gameCrashed = preferences.getBoolean("crashed", false); | |
//If the game crashed | |
if (gameCrashed) { | |
//Get the saved details | |
String playerName = preferences.getString("playerName", "Takis"); | |
int points = preferences.getInt("playerPoints", 0); | |
int level = preferences.getInt("level", 0); | |
//Reset the state | |
SharedPreferences.Editor editor = preferences.edit(); | |
editor.putBoolean("crashed", false); | |
editor.commit(); | |
} | |
} | |
//Setup lastBreath so that it saved the details as shared preferences | |
@Override | |
public void lastBreath() { | |
//We want to save the state of the game as shared preferences. | |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
SharedPreferences.Editor editor = preferences.edit(); | |
editor.putBoolean("crashed", true); | |
editor.putString("playerName", "Takis"); | |
editor.putInt("playerPoints", 24000); | |
editor.putInt("level", 6); | |
editor.commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment