Exiting the Game

This game doesn't really need an Exit button, because the user can just press the Back key or the Home key to do something else. But I wanted to add one to show you how to terminate an activity.

Add this to the switch statement in the onClick() method:

Download Sudokuv1/src/org/example/sudoku/Sudoku.java

case R.id.exit_button: finishO; break;

When the Exit button is selected, we call the finish() method. This shuts down the activity and returns control to the next activity on the Android application stack (usually the Home screen).

0 0

Post a comment