0

I have implemented a listView which shows items downloaded on my Webserver. The listView uses 'cache'(holder), I click on one item of my listView and an intent (new activity) is called. It's works perfectly, but when I come back to my listView from this activity, the onStart() is called and the download is called again (whereas I don't need it because I use 'cache').

How can I fix this problem? I need to call the webserver in a function that it doesn't call when I come back in this activity.

Thanks

Florent

user420574
  • 1,437
  • 5
  • 21
  • 33

1 Answers1

0

If you're trying to cache images between activities, there are two approaches:

  1. Write files out to the SD card - This might be handy if you want the images to still be there even after your activity ends and restarts. The downside is that you now have to manage the lifecycle of the images and make sure that you periodically delete them so that your cache directory doesn't keep growing.

  2. Use a service - I'm not sure how the performance with this method would be, and it tends to be a little more complicated. A service will keep on living while your activities come and go, holding your images in its memory. Read this answer for more about communicating with services.

  3. Store images in a static singleton - The quick and dirty way; Just make sure you don't store too many in memory or you'll get an out of memory exception.

I'd probably prefer method 1.

Also refer to this comprehensive answer.

Community
  • 1
  • 1
Matthew
  • 44,826
  • 10
  • 98
  • 87