[Android] Fragments navigation: allow state loss

Geoffrey Métais git at videolan.org
Wed Jan 16 11:26:23 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 16 11:24:05 2019 +0100| [494ece97378993e3062e8c1846fe0c8230c72b5f] | committer: Geoffrey Métais

Fragments navigation: allow state loss

> https://code.videolan.org/videolan/vlc-android/commit/494ece97378993e3062e8c1846fe0c8230c72b5f
---

 vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index df1e4c1a1..bf8c28c08 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -33,6 +33,8 @@ import androidx.fragment.app.FragmentManager
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleObserver
 import androidx.lifecycle.OnLifecycleEvent
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.ObsoleteCoroutinesApi
 import org.videolan.vlc.R
 import org.videolan.vlc.extensions.ExtensionManagerService
 import org.videolan.vlc.extensions.api.VLCExtensionItem
@@ -50,11 +52,13 @@ import org.videolan.vlc.util.*
 import java.lang.ref.WeakReference
 
 private const val TAG = "Navigator"
+ at ObsoleteCoroutinesApi
+ at ExperimentalCoroutinesApi
 class Navigator(private val activity: MainActivity,
-        private val settings: SharedPreferences,
-        private val extensionsService: ExtensionManagerService?,
-        state: Bundle?,
-        target: Int
+                private val settings: SharedPreferences,
+                private val extensionsService: ExtensionManagerService?,
+                state: Bundle?,
+                target: Int
 ): com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener, LifecycleObserver {
 
     private val fragmentsStack = SimpleArrayMap<String, WeakReference<Fragment>>()
@@ -111,7 +115,7 @@ class Navigator(private val activity: MainActivity,
             fm.popBackStackImmediate("root", FragmentManager.POP_BACK_STACK_INCLUSIVE)
         val ft = fm.beginTransaction()
         ft.replace(R.id.fragment_placeholder, fragment, tag)
-        ft.commitNow()
+        ft.commitAllowingStateLoss()
         activity.updateCheckedItem(id)
         currentFragment = fragment
         currentFragmentId = id



More information about the Android mailing list