I have a fragment in an activity where I create views dynamically and assign images to the image views after a user selects them from a gallery I created. However if the user hits the back button and then re-opens the fragment the views have all been reset and there are no images. Ive tried a couple different ways of handling the saved state but since Im dealing with potentially up to 20 images Im not sure how to handle the state of my fragment being that none of the methods ive tried seem to work. Right now Im trying to use Fragment.SavedState and just re instantiate using that but I cant figure out how to actually use the savedstate. Any help or advice on the matter would be much appreciated.
Share
The best thing to do would be to use an LRU cache, for best performance you would want to combine a memory based cache and a disk based cache. Jake Wharton has an excellent implementation here.
Once a Fragment/Activity is no longer visible it up for garbage collection, so you need to be able to rebuild the whole view. I would recommend testing with
Don't Keep Activitiesturned on in the Developer Options.There is an excellent example of loading images from the Network in BitmapFun on the Android Developer site.