Kotlin - Load and save data in activities when minimize or kill app

PressRex profile image
by PressRex
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

PressRex profile image
by PressRex

Subscribe to New Posts

Lorem ultrices malesuada sapien amet pulvinar quis. Feugiat etiam ullamcorper pharetra vitae nibh enim vel.

Success! Now Check Your Email

To complete Subscribe, click the confirmation link in your inbox. If it doesn’t arrive within 3 minutes, check your spam folder.

Ok, Thanks

Read More