开发者

AsyncTask Save Variables from doInBackground

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.


You can access the results of doInBackground in onPostExecute.

Simply change your class to:

public class YourTask extends AsyncTask<Void, Void, ObjectYouWantToReturn> {

    @Override
    protected ObjectYouWantToReturn doInBackground(Beneficiary... params) {        
        ObjectYouWantToReturn obj = new ObjectYouWantToReturn();
        //... do your stuff
        return obj;
    }

    @Override
    protected void onPostExecute(ObjectYouWantToReturn result) {
        //there you go, here you have the results from doInBackground
    }
}


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜