Hardware button input

Now, let's test out our hardware buttons along with a Toast example. Don't feel hungry yet reading Toast! It's not the one that you are going to eat. A Toast is a message that gets displayed on your screen for a few seconds and disappears. You will see what it is in a few minutes. So, now open up your FullscreenActivity.java file where you typed your onCreate code, and after your onCreate method, type the following:

    @Override    public void onBackPressed() {        // your code.        Toast.makeText(FullscreenActivity.this,         "Back button pressed", Toast.LENGTH_SHORT).show();    }

Observe the code here. In the first line, we have used the keyword @Override. This is because we are overriding the parent class functionality, which is the ...

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.