Universal-Image-Loader does not keep the displayed images - java

I am handling 3mb of images and the problem is by the time I release my finger from scrolling, the images, are somewhat downloaded from the cache in my case in the sd card. I am using PauseOnScrollListener, as well and it did not solve the problem. I wanted the images to remain on the grid even if I am not viewing it, while scrolling. Universal-Image-Loader handles it differently by not showing the images while not displayed, and by the time I pause and see a particular image then that's the time it gets displayed again.
options = new DisplayImageOptions.Builder()
.showStubImage(icon)
//Because you reuse view for different
//images you can see a previous image in the view while new image is loading. .resetViewBeforeLoading(true
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheOnDisc(true)
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();

If you are using a GridView, this is the normal behavior.
Actually what happens is that, when you scroll through, the elements that are not visible or which are scrolled out of the screen are destroyed or in other words nullified. The reason is memory optimization and this is done by android.
If you have any textview in your Grid Element, it will be loaded faster when it gets back into the screen. But for Images, the ImageLoader might take a little time to load the images from the cache into the ImageView. This is normal in my opinion.
If you don't want the images to be destroyed, then you will run into OutOfMemory exception for which this is much more better.

Related

Showing lists of image to RecyclerView from internet

I have a long list of images that i need to show in to recyclerView. I am using glide to show the images from my adapter.
Glide.with(context).load(feed.getImgLink()).diskCacheStrategy(DiskCacheStrategy.NONE).into(holder.myImgView);
The above is the code am using i set the DiskCacheStrategy to none because I'm trying to show Instagram like Feed and i didn't want to permanently cache the img on disk.
The first time i see the image there is no problem it is displayed normal but after i scroll down and back up the image reload again. I get that i haven't cache the image in to disk but there is still momery cache.
Is there any way i can solve i could use diskcache to ALL but it is taking space for just one time viewing.
Try this.
Glide.with(context).load(imageUrl).into(holder.myImgView);

Android Java recycle View scrolling: will it redownload images?

I am using picasso in my recycler view. I am wondering about the caching: When I scroll down the images disappear and when I scroll up again, they show again. But its displaying the progress bar for downloading and it takes like a second to show it.
my code
Picasso.get().load(profileUrl).placeholder(R.drawable.placeholder_image).fit().into(postViewHolder.profileImg);
I want to avoid downloading the same images multiple times. Or is it just the caching that takes some time to display the already cached image again?
Picasso should cache images automatically. You can can check if it's cached by using the setIndicatorsEnabled method on the Picasso singleton instance.
Red: Downloading over the network.
Blue: Image was cached on disc.
Green: Image was cached in memory.
Picasso by default cache image . if you dont want cache using this code
Picasso.with(context).load(uri).networkPolicy(NetworkPolicy.NO_CACHE).memoryPolicy(MemoryPlicy.NO_CACHE).placeholder(R.drawable.placeholder).into(imageView);

How to manage memory with too many items on android recycleview

I am developing an android social media type application, where I have a multiple tab activity. The tabs are fragments using viewpager.I have a home screen with a recycler view. The post have images on them. I am having memory problem with the recyclerview for post. I am using firebase as a database if thats helpful. To load the imageview I am using glide and I am doing diskcache and skipping the memory caches.
Issues I am having are
When too many posts are loaded, recyclerview becomes slow and laggy (I know that there are other post with this but couldnt really found anything helpful).
When I click on a username from the post, a new profile activity starts which also have all the posts from that user, I am trying to find a way clear the homepage tab recyclerview memory but struggleing with how to.
To solve the first problem, I have set up an onscrolllistner that loads 10 new post everytime you are near the end of the post list. The recycler view adapter currently loads 20 items initially and then so on.but I am not sure how to clear the old posts in an efficient way since I want the user to be able to scroll up.
To solve the second problem, In the homescreen fragment, when I launch the new activity, the onPause() function gets called. In the onpause() function I tried setting the list to empty, recyclerview adapter to null, recylerview to null but nothing has worked. In the android profiler tool, I see that I am using 200 mb memory, and when I start the new activity, it adds another 100 mb or so. I tried manual garbage collections but it doesnt work either. To be specific, native memory jumps up in the profiler. Ive tested and made sure that was only because of the images in the recyclerview.
I am not sure why when I set recyclerview, adapter and the post list to null, why the images from posts are still being held in the memory.
Glide caches the images
To load multiple post check paging library
When moving to detail fragment and clearing the reacyclerview of home fragment , I would not recommend this as next time user switches to home tab ,the user will not have previous state saved which he left previously.

How do I insert multiple image in Edit Text in android

I am trying to insert multiple images in one editText. I have used following code to attach image to EditText
txt = (EditText)findViewById(R.id.text);
Bitmap bitmap = BitmapFactory.decodeFile(attach);
Drawable drawable = new BitmapDrawable(bitmap);
txt.setBackgroundDrawable(drawable);
But the problem is it only attach one file and show, If i used array then only the last image is only show. at any how it only shows one Image. Is there any way to show multiple images in one Editbox. Thanks in advance.
Because you can only have one background.... if you want more then there is a layer Drawable which you can use and also you can put the button in a frame layout and add a couple of imageViews below/over it for the rest of the images.
But the best solution will probably be instead of having a couple of bitmaps to just make a single one in Photoshop or equivalent photo editing app and place that one.
According to docs: http://developer.android.com/reference/android/view/View.html#setBackgroundDrawable(android.graphics.drawable.Drawable)
You are not able to provide more than one Drawable item in argument
And I don't know if you understand what is .setBackgroundDrawable(d) method purpose, but it is not meant to be used for displaying images inside text but to set Background of EditText View.
So you're not inserting images in EditText but setting its background,
look for some Rich Text Edit components usable for Android
such as http://code.google.com/p/android-richtexteditor/
or others..
You can probably use a LayerDrawable with the constructor LayerDrawable(Drawable[] layers) to chain together several images and display them as an EditText's background, though as Marek said, I suspect you're looking for something other than setting images in the background.

Modifying single list items

I have a ListView, displaying some items, containing an ImageView filled with a standard image at first and a line of text.
What I wanna do is downloading one thumb after another with an AsyncTask and step for step change the standard image with the downloaded one. How to realise this?
The ListView contents are managed by an enhanced ArrayAdapter.
greetz
EnflamedSoul
If I understand you correctly you're interested in a LazyList. This example shows a stub for the image, then downloads some thumbnails as the user scrolls down and caches these onto an SD card. The next time the images will be loaded from the SD card.
Lazy load of images in ListView
I personally used Fedor's example and it worked well.

Categories