后退按钮将应用程序返回到不一致的状态
今天我正在测试我的应用程序(这是一个非常简单的笔记应用程序),但出现了一些奇怪的行为。
该应用程序由一个显示所有笔记的大 ListView 和一个用于创建新笔记的按钮(活动 A)组成。
当我按下“添加新笔记”按钮时,它会将我带到活动 B (包含标题和文本等所有字段)。
当我按“添加”时,它会带我回到活动 A 并显示 ok
新的注释。
问题是,我开始按“返回”,它开始带我“回到过去”,其中一些音符尚未创建,直到达到 0 个音符的时间。
由于我是 Android 开发新手,这是正常现象还是我的应用程序有问题?
Today I was testing my app (wich is a very simple note application) but some strange behaviour occur .
The app consists of a big ListView which displays all the notes and a button to make a new note (activity A).
When I press the button to "Add new note",it takes me to the activity B
(with all the fields like title and text).When I press "Add" ,it take me back to the activity A and displays ok
the new Note .
The thing is that I started pressing BACK and it began to take me "back in time" where some notes were still not created,until it reached the time they were 0 notes .
Since I am new to Android devel ,is this normal or is it something wrong with my app ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您从一项活动转到另一项活动时,您应该完成您的活动,然后开始新的活动。
尝试下面的代码:
When you go from one activity to another then you should finish your activity and then start new activity.
Try the below code:
您可能需要实现某种刷新方法来更新您的 ListView。根据保存数据的方式,您可以创建一个方法来检索最新数据,然后更新 ListView 的适配器。实现后,您应该调用
onResume()
中的方法。You probably need to implement some sort of refresh method to update your ListView. Depending on how you are persisting the data, you could create a method that retrieves the latest data and then updates the adapter for the ListView. Once you have that implemented, you should call the method in
onResume()
.