0

I am currently implementing an android application. When I press the home/overview buttons, the application pauses by default (showing the applications overview for the second one). I have noticed that most of the applications in recent android versions, give the ability of double tap on home and overview buttons. Specifically, when home/overview buttons are pressed, it pops up a toast message "Tap again to exit". Is this the default action of home/overview buttons. If so, how can I enable it in my application? If not, could I override the default behavior? It is mentioned in various posts that there is no ability of replacing home/overview button actions, since they are system default (that's why there are no handling methods like onBackPressed for back button).

  • No I mean the home and overview buttons."(that's why there are no handling methods like onBackPressed for back button)". Most of the full-screen applications that I have installed in my phone, have the ability to pop up a toast message, once home or overview buttons are pressed. – Alexandros Mavrommatis Dec 12 '20 at 11:50
  • In addition, all these applications somehow get a default toast message for exiting that is dependent on phone system language. Can someone locate system default messages through an app? – Alexandros Mavrommatis Dec 12 '20 at 12:48
  • They might show a toast inside on pause or on resume. As for the language thing, it is a string. – private static Dec 12 '20 at 13:36
  • @PrinceAli you say "as for the language thing, it is a string". You mean a system default string located somewhere, or string defined in the code or as a value in strings.xml. I am pretty sure that it is not the second one, since I tested various applications, implemented in various languages and they show the exit toast message in the system language. For example, I turned my phone language in french, and the toast exit message displayed in french for applications implemented in english as well as other languages (but not french). – Alexandros Mavrommatis Dec 12 '20 at 14:04
  • How can you tell French translation is not implemented in strings.xml? – private static Dec 12 '20 at 14:11
  • @PrinceAli Because I also tested for a greek application, implemented only in greek language. There is no way that the developers created this application in greek, have created a bunch of other strings.xml files only for exit toast message. I also tested the aforementioned application for chinese system language and it worked. Please do not tell me that greek developers created a strings.xml in chinese only for an exit toast message :P – Alexandros Mavrommatis Dec 12 '20 at 14:16
  • In that case, android.R.string.some_default_string might have been used. But Idk! – private static Dec 12 '20 at 14:19

1 Answers1

0

In your MainActivity, inside onPause/onResume methods.

@Override
    protected void onPause() {
        showToast("You paused the activity");
        super.onPause();
    }
    
    @Override
    protected void onResume() {
        showToast("You resumed the activity");
        super.onResume();
    }
    
    
    private void showToast(String str) {
        Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
    }

The previous methods will display a toast message saying you paused the activity when you press the back, home or overview buttons (onPause). Similarly if you re-enter the app, it will display you resumed the activity.

private static
  • 745
  • 8
  • 17
  • 1
    Exactly as you say, this will display a toast once the application is paused, not once home or overview buttons are pressed. I want a functionality that shows a toast once the buttons are pressed. In case that the application is paused due to another reason (i.e. you left the application due to a call), I don't want a toast message to be shown. I am definitely sure that this is feasible since many applications installed in my phone support this functionality. – Alexandros Mavrommatis Dec 12 '20 at 14:11
  • Makes total sense, but I haven't found anything that allows an app to utilize the home button. Well, at least not yet. – private static Dec 12 '20 at 14:14