如何避免 Android 设备后退按钮上的数据重新加载
我正在使用基于 Android 选项卡的应用程序和 TabGroupActivity,该应用程序有一个 ListActivity“A”,它可以深入到详细活动“D”,在详细活动上,当我单击设备后退按钮时,它导航回 ListActivtiy“A”并重新加载数据(进度条在后退按钮上显示进度)。
如何避免在后退按钮上重新加载数据?
任何帮助将不胜感激。
I am using android tab based application with TabGroupActivity, the application have a ListActivity "A" which drills down to a detail activity "D", on detail activity when i click device back button it navigate back to ListActivtiy "A" and relaods the data (ProgressBar shows progress on back button).
How can i avoid reloading of data on back buttuon ?
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你可以使用 onSaveInstanceState() 保存需要保存的内容,然后恢复 onCreate()
Perhaps you can use onSaveInstanceState() to save what's needed to be saved and then restore your activity in onCreate()
如果您查看 Activity LifeCycle :
当您转到另一个Activity,然后按返回,它会调用 finish()。第一个活动位于 onStop() 方法上,因为它不再可见。因此,当您返回到第一个 Activity 时,它将调用方法 onStart() 和 on Stop()。
尝试重载此方法而不调用 super 方法(这可能是一个非常糟糕的主意)。
您还可以尝试记住当时的位置(获取当前选项卡的索引),并在 onResume() 方法上将当前选项卡设置为该索引。
您只需要在列表活动中添加一个int 属性savedPosition。
私有 int 保存位置 = -1;
If you look at the Activity LifeCycle :
When you go to another activity, and press back, it will call finish(). The first activity was on the onStop() method because it was no longer visible. So, when you come back to the first activity, it will call the method onStart(), and on Stop().
Try to overload this method without calling the super method (it might be a very bad idea).
You can also try to remember the position when you was (get the index of the current tab), and on the onResume() method, set the current tab to this index.
You just need an int attribute savedPosition in your listactivity.
private int savedPosition = -1;