Kotlin - Load and save data in activities when minimize or kill app
I'm working on my first kotlin app with several activities. Each activity is composed of fields that the user fills in and saved into an SQLitedatabase I need help on when to save and reload data.
What I do :
In each activity, I save data when going back or when calling another activity.
binding.myButton.setOnClickListener{
saveData()
val intent = Intent(this, MyActivity::class.java)
startActivity(intent)
}
And I reload all the data on onCreate() and onResume().
override fun onResume() {
super.onResume()
loadData()
}
How to manage and determine when user minimize app ? I can use onStop() but it's also called when activity ends.
Same question when user kills the app ? onDestroy() is also used when activity ends
Thanks for your help
Source: View source