Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android press back 2 times to exit

boolean doubleBackToExitPressedOnce = false;

@Override
public void onBackPressed() {
    if (doubleBackToExitPressedOnce) {
        super.onBackPressed();
        return;
    }
        
    this.doubleBackToExitPressedOnce = true;
    Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
        
    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        
        @Override
        public void run() {
            doubleBackToExitPressedOnce=false;                       
        }
    }, 2000);
} 
Comment

PREVIOUS NEXT
Code Example
Java :: how use a if in java 
Java :: sort arrays by first element java 
Java :: retrofit post body 
Java :: string to words java 
Java :: take a peice from array java 
Java :: why static variables cannot be serialized in java 
Java :: hangfire list recurring jobs 
Java :: jdk jre jvm 
Java :: horizontalAlignment center jlabel 
Java :: final keyword in java 
Java :: double if statement java 
Java :: how to change background color of grid in grid layout in android 
Java :: mongodb spring boot index usage 0 
Java :: java variable 
Java :: how to find mongo java driver version 
Java :: Java telegram bot dependency 
Java :: index 1 out of bound for length 1 java 
Java :: import image icon 
Java :: java add constructor to enum 
Java :: random value between 10-20 
Java :: next line java does not take input 
Java :: string length java 
Java :: single level inheritance in java 
Java :: GridLayout 
Java :: void * to int 
Java :: array buffer 
Java :: instanceof java 
Java :: fabricmc concat text 
Java :: how to call the main method in java 
Java :: prefix vs postfix increment java 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =