Advanced Data Protection
You can combine the data-duplication and obfuscation techniques for added security. Ideally you should use a different XOR hash for the score and scoreCheck values. That will make it harder for a cheater to notice, otherwise the memory addresses will contain matching values and make it easier to find your checksum.
Example Code
private int xorCode = 12345; // USE A DIFFERENT XOR VALUE THAN THIS!
private int scoreCheckXorCode = 54321; // USE A DIFFERENT XOR VALUE THAN THIS!
private int score = 0;
private int scoreCheck = 0;
// Make sure to xor the initial values
@Override
private void onCreate(Bundle savedInstanceState) {
score = score ^ xorCode;
scoreCheck = scoreCheck ^ scoreCheckXorCode;
}
// Functions and mutators should xor the value before using it, and xor the value again before the function exits
private void addScore(int increase) {
score ^= xorCode;
score += increase;
score ^= xorCode;
scoreCheck ^= scoreCheckXorCode;
scoreCheck += increase;
scoreCheck ^= scoreCheckXorCode;
}
// Confirms that the score is valid.
private boolean confirmScoreValidity() {
return (score ^ xorCode) == (scoreCheck ^ scoreCheckXorCode);
}