diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index 94ba49f7b148..e2afccaf9f85 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -14,6 +14,7 @@
Show License
Show Notice
More Info
+ Press back again to quit
LibreOffice Browser
Search
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index a8f42765a873..8ceca05938c2 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -20,6 +20,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
@@ -96,6 +97,7 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa
ListView lv;
private final LOAbout mAbout;
+ private boolean canQuit = false;
public LibreOfficeUIActivity() {
mAbout = new LOAbout(this, true);
@@ -197,6 +199,31 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa
drawerLayout.closeDrawer(drawerList);
}
+ @Override
+ public void onBackPressed() {
+ if (!currentDirectory.equals(homeDirectory)) {
+ // navigate upwards in directory hierarchy
+ openParentDirectory();
+ } else {
+ // only exit if warning has been shown
+ if (canQuit) {
+ super.onBackPressed();
+ return;
+ }
+
+ // show warning about leaving the app and set a timer
+ Toast.makeText(this, R.string.back_again_to_quit,
+ Toast.LENGTH_SHORT).show();
+ canQuit = true;
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ canQuit = false;
+ }
+ }, 3000);
+ }
+ }
+
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {