Press Back Again to Exit App | Android Double Back Pressed to Exit or Leave the Application

Опубликовано: 15 Март 2026
на канале: Daily Coding
17,814
86

Press Again to Exit || In this video we'll learn how to enable Double Back Pressed to Exit or Close the Application from Activity.


@Override
public void onBackPressed() {

if (isBackPressedOnce) {
super.onBackPressed();
return;
}

Toast.makeText(this, "Press again to exit!!", Toast.LENGTH_SHORT).show();
isBackPressedOnce = true;

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
isBackPressedOnce = false;
}
}, 2000);

}

☕ Buy me a Coffee ☕
buymeacoffee.com/daily_coding

📌 Related Topics:
◀️ Android Activity Playlist
🔗    • Android Activity - Complete Guide  


📜 References:
🔗 Google Docs Link:

================*=***=*==================
💡 Why do you need to Subscribe to my channel?
1. It's free (you just need the google mail account)
2. Up to date (every my videos in your mail)
3. Help me to grow up this channel
4. More subscribers = More events.
5. Subscribe to channel DailyCoding
========================================

🔷🔷 JOIN NOW 🔷🔷
***************************************************
👉 Telegram Channel: https://t.me/DailyCodingYT
👉 Telegram Group: https://t.me/DailyCodingOfficial

👉 Facebook Page:   / dailycoding.in  
***************************************************

🙏 Thank you 🙏
#onBackPressed #DailyCoding #AndroidAppDevelopment