views:

96

answers:

2

Hi again friends... i have a wierd problem... As i have asked in previous posts... i have a lot of data coming from NET in my app... The problem is that a lot of text and images r there... so though i can make the user wait wen he clicks on a list item, but i dont want to make him wait wen he clicks the back button...

In the sense that i dont want to re-download all data... data 1ce downloaded should remain...

Which 1 is the rite method??
1. using a special class which stores all data... and using the variables 
each time i go back..

or-
2. Is there any specific save instance method for saving such data in the class 
itself... if it is then do inform me how to call the saved instance Activity 
wen back is clicked...

Thanx in advance guys... U already have been a great help...

A: 

By "user clicks the back button" I understand that the previous activity is displayed and returned at the top of the stack (see activity lifecycle).

This mean this activity is not created again, but resumed (unless it was killed by core because other applications need memory), so its fields and attributes keep their values. So if you store your datas in some activity fields, you might be able to retrieve their values and display them without re-download them.

Of course you have to test these fields before accessing them in order to avoid NPE in case of activity first start.

kosokund
Thanx Thomas... so i guess i won be needing to download the content again if i save images in a variable and check if its null... right...???
JaVadid
Yes you got it. Now try and accept my answer if it works! :)
kosokund
A: 

You shouldn't rely on any Activity already existing when you start it or return to it.

Check out this previous question about caching already-downloaded data:
http://stackoverflow.com/questions/1979731/what-is-the-ideal-place-to-cache-images

You shouldn't have any pauses in the UI anyway when the user enters an Activity; you should be doing all the downloading on a background thread and showing some sort of progress indicator to the user. If you don't do this and the UI thread is blocked by a slow download (about 15 seconds), the user will be presented with an "Application Not Responding" dialog and asked to either kill your application or keep waiting. Not good.

Christopher