Skip to content
Permalink
Browse files

AutoSave: Do not block on background save.

Android doesn't kill the process immediately after all foreground activities are gone. So we still have
time to save the state from our background thread.

This also avoids ANRs and issues we saw related to blocking the UI thread, e.g.:
mozilla-mobile/reference-browser#405
  • Loading branch information...
pocmo committed Jan 11, 2019
1 parent 3bfd308 commit ea811e089cd40c6d1fc9ec688fa5db3e7b023331
@@ -11,7 +11,6 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.session.SelectionAwareSessionObserver
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
@@ -171,11 +170,7 @@ private class AutoSaveBackground(
fun stop() {
autoSave.logger.info("Save: Background")

runBlocking {
// Since the app is going to the background and can get killed at any time, we do not want to delay saving
// the state to disk.
autoSave.triggerSave(delaySave = false).join()
}
autoSave.triggerSave(delaySave = false)
}
}

0 comments on commit ea811e0

Please sign in to comment.
You can’t perform that action at this time.