From 615bcfb666b1896705c27c8f14feb64b6620a4f9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 28 Apr 2014 22:24:28 -0400 Subject: [PATCH] try to find ManageRepo's Fragment before recreating it This helps with dealing with listFragment being null after a rotation. That was happening when an Intent was coming in from a QR Code scanner, and the screen was rotated during the process. This snippet was taken from SearchResults.java This is Peter Serwylo's idea, I just typed it up and tested it :) --- src/org/fdroid/fdroid/ManageRepo.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java index 733f0e063..64b025597 100644 --- a/src/org/fdroid/fdroid/ManageRepo.java +++ b/src/org/fdroid/fdroid/ManageRepo.java @@ -27,11 +27,11 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import android.support.v4.app.NavUtils; import android.text.TextUtils; import android.util.Log; import android.view.MenuItem; - import android.widget.LinearLayout; import android.widget.Toast; @@ -57,8 +57,8 @@ public class ManageRepo extends FragmentActivity { ((FDroidApp) getApplication()).applyTheme(this); - if (savedInstanceState == null) { - + FragmentManager fm = getSupportFragmentManager(); + if (fm.findFragmentById(android.R.id.content) == null) { // Need to set a dummy view (which will get overridden by the fragment manager // below) so that we can call setContentView(). This is a work around for // a (bug?) thing in 3.0, 3.1 which requires setContentView to be invoked before @@ -67,10 +67,9 @@ public class ManageRepo extends FragmentActivity { setContentView( new LinearLayout(this) ); listFragment = new RepoListFragment(); - getSupportFragmentManager() - .beginTransaction() - .add(android.R.id.content, listFragment) - .commit(); + fm.beginTransaction() + .add(android.R.id.content, listFragment) + .commit(); } ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);