Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data saving during Activity life cycle

Tags:

android

What is the common approach to save user's inputed data: 1. Overriding onPause() method with subsequent calling to specially designed method to store data using Android Preferences OR 2. Usage of onSaveInstanceState() and onRestoreInstanceState()?

Thank you very much.

like image 953
Eugene Avatar asked Feb 26 '23 12:02

Eugene


1 Answers

Usually onPause() is used to save persistent data and onSaveInstanceState() is used to save dynamic data. Note that onSaveInstanceState() is not always called before an activity goes to the background.

There is a good explanation for these methods in the documentation of Activity.

like image 139
Sergey Glotov Avatar answered Mar 08 '23 09:03

Sergey Glotov