Skip to content

Instantly share code, notes, and snippets.

@ifinoi
Created January 7, 2013 12:05
Show Gist options
  • Save ifinoi/4474515 to your computer and use it in GitHub Desktop.
Save ifinoi/4474515 to your computer and use it in GitHub Desktop.
Implementation of LastBreath in game
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