开发者

Data saving during Activity life cycle

开发者 https://www.devze.com 2023-02-01 20:26 出处:网络
What is the common approach to save user\'s inpu开发者_开发技巧ted data: 1. Overriding onPause() method with subsequent calling to specially designed method to store data using Android Preferences

What is the common approach to save user's inpu开发者_开发技巧ted 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.


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.


Check out Android - Lifecycle and saving an Instance State questions. As for me, I am doing it in onPause / onCreate. Can't recall if there were problems with the onSaveInstanceState() / onRestoreInstanceState() pair but I think there were.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号