How to Prevent Accidental App Exit w/in Android Fragments/Activities?
问题 How Do I Prevent Accidental App Exit w/in Android? IE: When the he/she presses the back button and reaches the last activity in the BackStack, show a toast to ask if the user wants to exit using the onBackPressed() method. Also, It needs to function with backStacks for fragments. 回答1: This functionality can easily be implemented by overriding main activity's onBackPressed() method. In this example when user presses back button then the app will display a toast for 4 seconds on which time a