Vitor Pamplona on Nostr: TLDR: Don't keep things running in the background on Android if you can avoid it. ...
TLDR: Don't keep things running in the background on Android if you can avoid it.
Android kills anything that runs in the background frequently. Even the background tasks are killed and restarted here and there. Your app is assumed to be able to recover to the exact same screen when that happens and the user opens it again. You can never trust the OS to keep the app open or in memory. In serious apps, even the state of the interface, is saved to the disk.
On Kotlin, the OS will try to tell you that it is killing parts of the app with the onStop() functions. This should give you time to save things before the actuall kill. But I have found that the onStop is not actually called in many instances, leaving an inconsistent state of the app.
Also, keep in mind that multiple phone manufacturers have different killing schedules implemented.
Android kills anything that runs in the background frequently. Even the background tasks are killed and restarted here and there. Your app is assumed to be able to recover to the exact same screen when that happens and the user opens it again. You can never trust the OS to keep the app open or in memory. In serious apps, even the state of the interface, is saved to the disk.
On Kotlin, the OS will try to tell you that it is killing parts of the app with the onStop() functions. This should give you time to save things before the actuall kill. But I have found that the onStop is not actually called in many instances, leaving an inconsistent state of the app.
Also, keep in mind that multiple phone manufacturers have different killing schedules implemented.