0

My Application gets images by json/url and populate a ListView along some TextViews. On each item click a new details_activity is open with an ImageView to display the image from the row. Then I open this image from ImageView in a new activity with fullscreen size.

My question is: Do I need to use the Universal Image Loader code below on all activities mentioned above?

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(true).cacheInMemory(true) .imageScaleType(ImageScaleType.EXACTLY) .displayer(new FadeInBitmapDisplayer(300)).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getApplicationContext()) .defaultDisplayImageOptions(defaultOptions) .memoryCache(new WeakMemoryCache()) .diskCacheSize(52428800).build(); ImageLoader.getInstance().init(config); 

What is happening is that sometimes I get out of memory error displaying fullscreen images. But if I return to details_activity and then click again on image, it opens with no error in fullscreen_activity, even if I use the code above on all activities that use imageloader.

6
  • You could use universal image loader to populate your listview. after that just pass the image url via intent to the nextactivity and set it to imageview.! Commented May 28, 2015 at 7:50
  • @DhinakaranThennarasu: Should I write the code on CustomListAdapter class or on ListView class? Commented May 28, 2015 at 8:02
  • @Skynet : Only defaultOptions or all the code (ImageLoaderConfiguration config...) ? Commented May 28, 2015 at 8:03
  • I am sorry the config needs to be loaded once, default options for each Class. Commented May 28, 2015 at 8:46
  • Tell me what you think: I did the way you told me. It works perfectly in genymotion with android 4.4. In android default emulator with android 4.0 the problem is happening sometimes. Yesterday I created an android default emulator with android L (Api 21) and it looked to work fine. Is this an emulator or API problem @Skynet? Commented May 28, 2015 at 16:34

1 Answer 1

1

Simply use Glide and avoid the extra codes and memory issue.

Example code (just 1 line!):

Glide.with(this).load("https://lh6.ggpht.com/9SZhHdv4URtBzRmXpnWxZcYhkgTQurFuuQ8OR7WZ3R7fyTmha77dYkVvcuqMu3DLvMQ=w300").into(imageView); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.