Browse Source

handle back press correct

tobiasKaminsky 8 years ago
parent
commit
64fad91842

+ 11 - 0
src/main/java/com/owncloud/android/ui/activity/ContactsPreferenceActivity.java

@@ -26,6 +26,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.support.design.widget.BottomNavigationView;
+import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.view.View;
 
@@ -54,6 +55,7 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
 
     public static final String PREFERENCE_CONTACTS_AUTOMATIC_BACKUP = "PREFERENCE_CONTACTS_AUTOMATIC_BACKUP";
     public static final String PREFERENCE_CONTACTS_LAST_BACKUP = "PREFERENCE_CONTACTS_LAST_BACKUP";
+    public static final String BACKUP_TO_LIST = "BACKUP_TO_LIST";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -158,4 +160,13 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
     public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
         // not needed
     }
+
+    @Override
+    public void onBackPressed() {
+        if (getSupportFragmentManager().findFragmentByTag(ContactListFragment.TAG) != null) {
+            getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+        } else {
+            finish();
+        }
+    }
 }

+ 5 - 6
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java

@@ -29,7 +29,6 @@ import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
 import android.support.v7.widget.AppCompatButton;
 import android.support.v7.widget.SwitchCompat;
 import android.view.LayoutInflater;
@@ -450,11 +449,11 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
             Fragment contactListFragment = ContactListFragment.newInstance(backupToRestore,
                     contactsPreferenceActivity.getAccount());
 
-            FragmentTransaction transaction = contactsPreferenceActivity.getSupportFragmentManager().
-                    beginTransaction();
-            transaction.replace(R.id.frame_container, contactListFragment);
-            transaction.addToBackStack(null);
-            transaction.commit();
+            contactsPreferenceActivity.getSupportFragmentManager().
+                    beginTransaction()
+                    .replace(R.id.frame_container, contactListFragment, ContactListFragment.TAG)
+                    .addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST)
+                    .commit();
         } else {
             Toast.makeText(contactsPreferenceActivity, R.string.contacts_preferences_no_file_found,
                     Toast.LENGTH_SHORT).show();