diff options
author | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-29 22:22:16 +0200 |
---|---|---|
committer | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-29 22:22:16 +0200 |
commit | 0ca89e916444d5e3f42238d36039e53903555276 (patch) | |
tree | 5ba4a2498dfd537fe3daa0f53f850ebde745f5f6 /app/src/main | |
parent | 14e6b8b0171601c7392d13c4c79e38c2e55df928 (diff) |
Fixed fragment resetting on rotation
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/MainActivity.java | 22 |
1 files changed, 12 insertions, 10 deletions
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( |