package com.example.ballcatchgame; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class result extends AppCompatActivity { private TextView scoreLabel,highScoreLabel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); scoreLabel = findViewById(R.id.scoreLabel); highScoreLabel = findViewById(R.id.highScoreLabel); int score = getIntent().getIntExtra("SCORE",0); scoreLabel.setText(score + ""); SharedPreferences settings = getSharedPreferences("GAME_DATA", Context.MODE_PRIVATE); int highScore = settings.getInt("HIGH_SCORE",0); if(score > highScore){ highScoreLabel.setText("High Score : " + score); //Save the new high score SharedPreferences.Editor editor = settings.edit(); editor.putInt("HIGH_SCORE",score); editor.commit(); }else{ highScoreLabel.setText("High Score : " + highScore); } } public void tryAgain(View view){ startActivity(new Intent(getApplicationContext(),start.class)); } }