AsyncTask 从 doInBackground 保存变量
我的 Activity 中有两个 AsyncTasks 作为内部类。在 doInBackground
中返回一个 ArrayList
,并在 postExecute
上为其分配一个 ListAdapter
。另一个 AsyncTask
返回一个 StringArray
并设置一些 TextViews
。
旋转时一切都消失了,旋转时布局也发生了变化。
我想访问 doInBackground
方法的结果。如果我有访问权限,我可以简单地将变量保存在 onSaveInstanceState
中并手动重新分配值。
I have two AsyncTasks
as inner classes in my Activity
. One returns an ArrayList
in doInBackground
and asigns a ListAdapter
to it on postExecute
. The other AsyncTask
returns a StringArray
and sets some TextViews
.
On Rotation everything is gone, also the layout changes on Rotation.
I'd like to have access to the results of the doInBackground
-Methods. If I had access I could just simply save the variables in onSaveInstanceState
and reasign the values manually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在
onPostExecute
中访问doInBackground
的结果。只需将您的班级更改为:
You can access the results of
doInBackground
inonPostExecute
.Simply change your class to:
我认为共享偏好可以解决您的问题。
修改下面给出的链接。
http://developer.android.com/guide/topics/data /data-storage.html#pref
http://thedevelopersinfo.com/2009/11/25/getting-sharedpreferences-from-other-application-in-android/
Shared preferences is solution of your problem i think.
revise the link given below.
http://developer.android.com/guide/topics/data/data-storage.html#pref
http://thedevelopersinfo.com/2009/11/25/getting-sharedpreferences-from-other-application-in-android/