This question has already been answered:

It is necessary to display the following notification on android on java http://m.imgur.com/V6aIHnL

Reported as a duplicate by participants of Streletz , Jurijspb , katso , pavlofff android 24 Sep '16 at 9:53 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    private static long back_pressed; @Override public void onBackPressed() { if (back_pressed + 2000 > System.currentTimeMillis()) super.onDestroy(); else Toast.makeText(getBaseContext(), "Нажмите еще раз для выхода", Toast.LENGTH_SHORT).show(); back_pressed = System.currentTimeMillis(); }