From 3a189d1af4d00089ba6805719f6a9dea3b0f8481 Mon Sep 17 00:00:00 2001 From: Erik Duisters Date: Fri, 7 Dec 2018 18:13:28 +0100 Subject: [PATCH] Do not create a new content fragment on orientation change Summary: When an orientation change occurs the fragment manager will automatically re-create the content fragment for us. Test Plan: Set the content fragment to DeviceFragment and change orientation Result: DeviceFragment is shown for the correct device and the correct navigation view menu item is checked Set the content fragment to PairingFragment and change orientation Result: PairingFragment is shown for the correct device and the "Pair new device" navigation view menu item is checked Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17409 --- .../kde/kdeconnect/UserInterface/MainActivity.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/org/kde/kdeconnect/UserInterface/MainActivity.java b/src/org/kde/kdeconnect/UserInterface/MainActivity.java index 46fdc9eb..bfbca979 100644 --- a/src/org/kde/kdeconnect/UserInterface/MainActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/MainActivity.java @@ -127,7 +127,6 @@ public class MainActivity extends AppCompatActivity { }); // Decide which menu entry should be selected at start - String savedDevice; int savedMenuEntry; if (getIntent().hasExtra("forceOverview")) { @@ -157,14 +156,19 @@ public class MainActivity extends AppCompatActivity { savedMenuEntry = (savedDevice != null)? MENU_ENTRY_DEVICE_UNKNOWN : MENU_ENTRY_ADD_DEVICE; } + mCurrentMenuEntry = savedMenuEntry; + mCurrentDevice = savedDevice; + mNavigationView.setCheckedItem(savedMenuEntry); + + //FragmentManager will restore whatever fragment was there + if (savedInstanceState != null) { + return; + } // Activate the chosen fragment and select the entry in the menu - if (savedMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID && savedDevice != null) { onDeviceSelected(savedDevice); } else { - mCurrentMenuEntry = savedMenuEntry; - mNavigationView.setCheckedItem(savedMenuEntry); if (mCurrentMenuEntry == MENU_ENTRY_SETTINGS) { setContentFragment(new SettingsFragment()); } else { @@ -226,7 +230,6 @@ public class MainActivity extends AppCompatActivity { } private void updateDeviceList() { - BackgroundService.RunCommand(MainActivity.this, service -> { Menu menu = mNavigationView.getMenu();