For this case I would simply use SharedPrefs to store your data.
Try this - here is the relevant part of your code with my addition:
if(Integer.parseInt(userInput.getText().toString()) == compNumber){
resultAlert.setTitle("Result");
resultAlert.setIcon(R.drawable.correct);
resultAlert.setMessage("Correct answer. The number is " + compNumber);
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);
int userScore = pref.getInt("score", 0); // getting last score from the SharedPrefs, if there is no previous score it sets it to 0
userScore++;
Editor editor = pref.edit();
editor.putInt("score", userScore); // Storing the new user score
editor.commit(); //saving the changes
System.out.println("========================================user score: "+userScore);
//CHANGE THE ACTIVITY
resultAlert.setPositiveButton("Play Again", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = getIntent();
startActivity(intent);
}
});
resultAlert.show();
That should take care of that... Take note that the SharedPrefs data remains after application is closed, so if at any time you need to reset the data stored just delete the entry in it using:
editor.remove("score"); // will delete the score entry
editor.commit(); // commit changes
Hope this helped!