From 0ca89e916444d5e3f42238d36039e53903555276 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Thu, 29 Mar 2018 22:22:16 +0200 Subject: Fixed fragment resetting on rotation --- .../org/marcinzelent/liberavem/MainActivity.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'app/src/main/java/org') diff --git a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java index 2b8cc38..dc261c5 100644 --- a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java +++ b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java @@ -30,17 +30,19 @@ public class MainActivity extends AppCompatActivity Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - Fragment fragment = null; - Class fragmentClass = null; - fragmentClass = ObservationsFragment.class; - try { - fragment = (Fragment) fragmentClass.newInstance(); - } catch (Exception e) { - e.printStackTrace(); - } + if (savedInstanceState ==null) { + Fragment fragment = null; + Class fragmentClass = null; + fragmentClass = ObservationsFragment.class; + try { + fragment = (Fragment) fragmentClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } - FragmentManager fragmentManager = getSupportFragmentManager(); - fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); + } DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( -- cgit v1.2.3