保存TextView的状态
我正在创建一个应用程序,在一个活动中,每次用户输入一条新信息时,文本视图都会不断变化。当按下后退按钮返回主菜单并且用户重新进入 Activity 时,它会重新创建并从头开始,而不是从用户离开的地方开始。 任何帮助将不胜感激! 谢谢你们!
Im creating a app that in one activity the text view is constantly changing everytime the user enters a new piece of imformation. When the back button is pressed to return to the main menu, and the user re-enters the activity, it is recreated and starts from the beginning instead of where the user left off.
Any help would be greatly appreciated!
Thanks Guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那一定是,因为每次都会重新分配 TextView
它再次显示。
如果您只创建实例一次,它
将会被拯救。
最好将 TextView 保存到类实例的属性中,等等。
干杯,
尼克拉斯
That must be, because of reallocation of the TextView every time
it's shown again.
If you only create the instance once, it
will be saved.
Best, you save the TextView to an attribute of a class instance, or so.
Cheers,
Niklas
好吧,我想通了。
问题是后退按钮完成了活动。我所做的是覆盖 onBackPress 按钮,然后启动主菜单活动以返回主菜单。这允许保存新活动的状态,并且当用户单击返回到活动时,数据仍然存在并且持久。这将回答有关尝试在 backButtonPressed 上保存的所有问题。如果您有任何其他问题,请告诉我,我很乐意为您提供帮助。
Okay so ive figured it out.
The problem was that the back button finished the activity. What i did was override the onBackPress button and then started the main menu activity to return to the main menu. This allowed the state of the new activity to be saved and when the user clicks to return to the activity the data is still there and persistant. This will answer all the questions about trying to save on backButtonPressed. If you have any other questions just let me know and ill be glad to help.