Skip to content

Commit

Permalink
Fix app returning to WebViewFragment when activity restarts
Browse files Browse the repository at this point in the history
`repeatOnLifecycle(Lifecycle.State.STARTED)` caused the flow collection to be restarted after the activity was stopped and then started again (for example, when opening another activity on top and then going back).
However, this triggered `handleServerState` with the current state again, which unintentionally replaced the current fragment (for example the player or settings) with the WebViewFragment.
The solution is to permanently collect the latest server state, but delay its application to the lifecycle start of the activity.
  • Loading branch information
Maxr1998 committed Aug 24, 2023
1 parent 03a0f3b commit 095ce01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/org/jellyfin/mobile/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.lifecycle.withStarted
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.jellyfin.mobile.events.ActivityEventHandler
import org.jellyfin.mobile.player.cast.Chromecast
Expand Down Expand Up @@ -88,8 +88,8 @@ class MainActivity : AppCompatActivity() {

// Load UI
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
mainViewModel.serverState.collect { state ->
mainViewModel.serverState.collectLatest { state ->
lifecycle.withStarted {
handleServerState(state)
}
}
Expand Down

0 comments on commit 095ce01

Please sign in to comment.