Android 应用程序从后台运行后表现得很疯狂
我正在显示来自网络服务的搜索结果。
我所做的是OnCreate,我点击了webservice显示记录,因为android支持多任务。如果用户打开另一个屏幕,一段时间后返回到搜索结果页面,应用程序开始表现得疯狂......
OnCreate 方法我加载数据,例如:
private void loadData() throws Throwable{
try {
jsonArray = JSONService.getJsonArray(getResources().getString(R.string.catJson));
} catch (Throwable e) {
Log.e(TAG, e.getMessage());
throw e;
}
}
然后我迭代 json 数组并更改标签值以在其上显示结果屏幕。
有什么想法如何解决这个问题吗?
I am displaying search results from a webservice.
What I do is OnCreate I hit the webservice display records, as android supports multitasking. If user opens another screen and after some time comes back to the search results page, the application starts acting crazy....
OnCreate method I load data some thing like :
private void loadData() throws Throwable{
try {
jsonArray = JSONService.getJsonArray(getResources().getString(R.string.catJson));
} catch (Throwable e) {
Log.e(TAG, e.getMessage());
throw e;
}
}
and then I iterate through json array and change labels value to display result on the screen.
Any ideas how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,请更好地解释我们的问题。您熟悉 Activity 生命周期吗?为了使多任务处理的概念真正发挥作用,您必须管理几种不同的回调。根据您提供的有限信息,我认为当您的活动失去焦点时您不会保存任何应用程序状态。因此,您的进程可能会关闭,当您回来时,您的 JSON 数组就消失了。读这个:
http://developer.android.com/guide/topics/fundamentals.html#循环
Yes, please explain our problem better. Are you familiar with the Activity life-cycle? There are several different callbacks that you must manage in order for your concept of multitasking to actually work. Based on the limited info you've provided, I don't think you're saving any of your application state when your Activity loses focus. So your process may be getting shutdown and when you come back, your JSON array is gone. Read this:
http://developer.android.com/guide/topics/fundamentals.html#lcycles
你在 OnCreate 中调用 super 吗?
Are you calling the super in your OnCreate?