views:

53

answers:

1

hi, i have two activities 1) downloading something on oncreate function with help of asyn task ,and had one button. 2) secons activity display on click of button. now when i go back to previous ie first activity , then downloading starts again, i want to get the previous filled data view ,instead of startg the previous process again .. canu please guide me thanks

+1  A: 

You should set a default value to whatever it is you're downloading, for example a default image, text or number, and then before downloading again, check whether the stored value is the default one or something new. If it's new, then you don't have to download again.

For example, in my game I have a similar thing. It's a jigsaw puzzle game with many images, where all the images are displayed in a ListView. To save space, I didn't include both the full size image and a thumbnail, but instead generate the thumbnails when the game loads and saved in a Bitmap[] array. So that bitmap generation process is similar to your downloading.

Whenever my game is about to load a list or access the images, it first checks whether the array is null. If it is, then it restarts the loading process. If it isn't, then it can use them. This is done with a simple check in onResume():

if (imageThumbnails == null) {
    // Do something to reload the images
} else {
    //the images are available, so they can be used
}

You should be able to do something similar for your app.

Steve H