Do I need to delete files downloaded over http with picasso? - android

I am making an app that acts somewhat like a gallery, but the images are going to be stored on a Firebase database. I am using Picasso to make this easier. Each image can be quite large in size, and there are a lot of them.
I am currently using fragments on a viewpager to display the images, and also a FragmentStatePagerAdapter. I know the adapter gets rid of the fragments, but I was wondering whether I had to delete the images I downloaded from device storage, and if so how. (I don't know exactly how Picasso works)
I'm sorry if this is a stupid/obvious question but I'm paranoid about clogging up memory and I've looked around the internet to no avail.
Thanks a lot!

Try this
Picasso.with(this)
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView);
or you can do something like this
mPicasso.with(appContext).invalidate(url);

Related

How to load images from internet in android app quickly?

I'm a beginner in android and i want to load some images from internet in my app. I heard about libraries such as Glide and Picasso. Can anyone please tell me which library is the best.
In your title you use the word "quickly". Theres no such thing, unless you have a cache implementation. As you pointed out those two libraries help in retrieving images from the web and displaying them into imageView, also support cache features so that images previously displayed can load faster in the near future.
Simple example of Picasso:
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
Want to know more about cache in Picasso? Check out this answer
According to this article here both are really nice to be used , but I would suggest Picasso because it just updated to 3.0 + it is lighter than Glide when it comes to :
library size and method count .

Picasso and thumbnails. Best practice

Picasso and thumbnails
Currently I am working of support of old project created by other developers.
I have task to improve images processing.
I can see there, that app creates resized small copy for every image downloaded from server for thumbnails using.
Then images loaded to ImageView with using of BitmapFactory.decodeFile in recycler view.
I know about Picasso and that this is the good practice to use it.
I believe that using of Picasso for creation of thumbnails images for list from original image is better
than creation of separate resized thumbnail for every image.
Is i am correct or maybe wrong ?
You don't have to reinvent the wheel.
If you have to deal with multiples images (for example: a list of images), resize, etc, I think that Picasso is a good option. This library has the best practice in resize, crop, memory leak related with Image.
Of course, is on your own, but you have to use it when it's possible
Nice coding!

Android, loading images efficiently in a list adapter

I am writing an android app. I have an ArrayAdapter which I am using to display a list of items where part of each item is an image. I am downloading the images asynchronously in the adapers getView() method and I am using a cache to keep it as efficient as possible and stop too many re-downloads. The problem I am facing is that the getView() method for each item can be called by android as many times as it needs to. It is often called faster than the image can actually download and so the same image can be queued many times for download before it even gets into the cache. Is there a best practice for how to prevent the images from being queued for download repeatedly? It just seems like a big waste of mobile data.
If you want to use third party image downloader library then you can use Picasso
Its actullay pretty neat and simple to use. It does caching for your app.
You can refer this tutorial.
Happy learning :)
The accepted best practice that is recommend by Google for downloading and displaying images in a list or recyclerview is to use the Glide library
https://github.com/bumptech/glide
The api looks like this
Glide.with(context)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.crossFade()
.into(myImageView);

Jittery scrolling when loading local images in recyclerView using Picasso

I am loading images in a recyclerView using picasso in my app. The image files are all local files. The problem is that the listview scrolling is not smooth, it is jittery. I searched about it and I saw that a lot of people have had similar problems but it is really strange that there is no clear solution available.
Horrible performance when loading local files
Picasso is awesome, but for loading local device images as thumbnails into a gridview (for example), Picasso is slower ...
Recyclerview painfully slow to load cached images form Picasso
From the above links it seems that picasso works great when fetching images from the web but for locally stored images it doesn't do that great.
Is it even recommended to use Picasso in this case? Should I have my own implementation of LruCache and remove Picasso? I have done it without Picasso using caching myself using LruCache. Though the scrolling is flawless in that case but Picasso is much more clean and compact, so I thought it might be the better solution in the long term.
There could a lot of reasons for this kind of behaviour. One issue could be that your row layout may be very deep rather than being wide. Another issue could be the size of images, if images are of large size, there is a good chance that all of them might not fit into Picasso's cache.
If the problem is due to the size of images, you can try Fresco by Facebook. It is very good at loading large images. It uses native as well as ashmem cache, so it can hold large amounts of images in cache compared to other similar libraries like Picasso or Glide. Another thing you can do is, android:largeHeap="true" in your AndroidManifest.xml inside the Application tag.

How do I use Picasso Image Caching?

I need to access an image that has been cached after it has been transformed (or cropped) using Picasso.
What I am doing is taking a large image resource, cropping a screen-size piece of it out of it at run-time, and setting it to the background of a RelativeLayout. So far I have used Picasso to accomplish this successfully.
Later in the app, I change the app layout by calling:
setContentView(R.layout.OTHER_LAYOUT);
I would like to then access the cache where Picasso stored the cropped version of the image, and dynamically set the background of OTHER_LAYOUT to the stored version of the cropped image.
This S.O. post seems relevant to accessing a bitmap cached by Picasso on device.
I am considering giving this solution a try. But one user's comment (a comment on the accepted answer) makes me wonder if there is a better way. Complicated solutions often seem more bug-prone.
"it seems can work. but in my opinion, it is not well offer. files are being saved somewhere. lib should give them to developers. it would be good instead of adding millions feature to picasso lib, adding very simple and essential features. I gave up to use picasso because of this. It has millions garbage features and very limited nice features."
Is there some way that Picasso allows me to access the image that was transformed and cached, and use it somewhere else (in a way that is simple & easy to use)?
If not, would another library give me greater convenience?
Don't think too much about reusing cached images, Picasso is very good at that and is well optimized for it. Just load the same URL / drawable and apply the transformation. If Picasso already cached it, it will be very fast, you can check if it is cached by setIndicatorsEnabled(true) on Picasso instance.

Categories

Resources