开发者

How to navigate between views? without losing data of the initial view

开发者 https://www.devze.com 2023-01-13 14:51 出处:网络
I have a login page which has a Advanced button. The button sets a view where a user can add some information.

I have a login page which has a Advanced button. The button sets a view where a user can add some information. When I click save, it goes back to my main view (loginpage) and all info is cleared?

How can I save the state of the first view when navigating away and then back to it?

Thanks开发者_如何学JAVA


Take a look at the activity lifecycle, described in the activity docs. When an activity goes into the background, as when you start a new activity, it can be deleted and will be recreated when the user goes back to the activity.

Additionally, your view will be recreated when you go through a configuration change, like a change in orientation.

In your case, you probably want to save the state in the onPause() method, and reset it in the onResume() method. One easy way to share state between activities, is via SharedPreferences. See Saving Persistent State for an example.

0

精彩评论

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