向导式活动和 onSaveInstanceState
我以“向导式”实现了多个活动,也就是说,底部有一个下一个和一个上一个按钮,可以使用以下按钮在它们之间导航:
Intent NextActivityIntent = new Intent(v.getContext(), FormN.class);
startActivity(NextActivityIntent);
我面临的问题是,当我返回活动时,字段已完成之前都是空的。
问题是,除了拦截 onSaveInstanceState 和 onRestoreInstanceState 事件并手动保存/恢复每个字段之外,是否有更简单的方法来继续显示字段值?
I implemented several activities in a "wizard-style", that is, there's a next and a previous button at the bottom to navigate between them using:
Intent NextActivityIntent = new Intent(v.getContext(), FormN.class);
startActivity(NextActivityIntent);
The problem I'm facing is that when I go back to an Activity, the fields completed previously are empty.
The question is, is there a simpler way to keep displaying the field values other than intercepting the onSaveInstanceState and onRestoreInstanceState events and save/restore every field manually ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 startActivityForResult 而不是 startActivity。先前的活动及其状态将保留在堆栈中。要从当前活动返回,请使用finish()。
理想情况下,您应该为 onSaveInstanceState 编写代码,以防手机重新定向。即使您锁定手机方向也没关系。
Use startActivityForResult instead of startActivity. The previous activity and its state would remain in the stack. For going back from your current activity use finish().
Ideally, you should code for onSaveInstanceState in case the phone gets re-oriented. Doesn't matter if you lock your phone orientation though.