How To Load Layout Background Using Picasso and cache it

Ening Source

I have View (LinearView) with a drawable on it's background. How can I save Drawable in onSaveInstanceState to increase showing speed? Actually picture is downloaded from the Internet, and when it's downloaded it is set as View background. If background!=null in onResume() I shouldn't load it from the Internet again.

I tried Picasso, but I need to load image into View, not ImageView, so I used something like this:

final ImageView img = new ImageView(view.getContext());
        .into(img, new com.squareup.picasso.Callback() {
            public void onSuccess() {

            public void onError() {

It downloads image, but it doesn't seem that it's caching it, every loading takes about 4 sec...

Also I tried to use MyClass implements Picasso.Target , but it just doesn't call onBitmapLoaded() method. Where can be a problem?

Thanks everyone for answers in advance!



answered 6 months ago 0x7067 #1

Before .into add .networkPolicy(NetworkPolicy.OFFLINE)

Like this:

        .into(img, new com.squareup.picasso.Callback() {

Read more

comments powered by Disqus