Skip to content

Instantly share code, notes, and snippets.

View ChintanRathod's full-sized avatar
🎯
Focusing

Chintan Rathod ChintanRathod

🎯
Focusing
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
@ChintanRathod
ChintanRathod / DoubleBackPressExit
Created April 8, 2015 08:27
To prevent user exit from activity with single "back" press, following short of code will ask to press another time "back" button to exit.
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press once again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override