3

I want to remove the cache from simple drawee using Fresco library because if image are changed from server then still show old image in simple drawee. Below are my code.

    public class FrescoSimpleDraweeActivity extends Activity {

    private SimpleDraweeView simpleDraweeView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_fresco_simple_drawee);


        Log.e("Fresco simple activity ","is calling...");

        simpleDraweeView1 = (SimpleDraweeView) findViewById(R.id.simpleDraweeView1);

        Uri imageUri = Uri.parse("http://i.imgur.com/76Jfv9b.jpg");
//        simpleDraweeView1.setImageURI(imageUri);


        //If we used to load image from network then use it otherwiese not.
        // return immidiate result if thumb store using (.setProgressiveRenderingEnabled(true)) (only local URI)

        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageUri)
                .setProgressiveRenderingEnabled(true)
                .setLocalThumbnailPreviewsEnabled(true)
                .build();

        ControllerListener listener = new BaseControllerListener();

        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(imageUri)
                .setImageRequest(request)
                .setTapToRetryEnabled(true)
                .setOldController(simpleDraweeView1.getController())
                .setControllerListener(listener)
                .setTapToRetryEnabled(true)
                .build();

        simpleDraweeView1.setController(controller);



    }
}

Here is my xml code

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity.Fresco.FrescoSimpleDraweeActivity">

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="This is Fresco Drawee Example" />
    <!--fresco:failureImage="@drawable/failure"-->

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/simpleDraweeView1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        fresco:failureImage="@drawable/failure"
        fresco:progressBarImage="@drawable/progress"
        fresco:progressBarImageScaleType="centerInside"
        fresco:roundAsCircle="true"
        fresco:roundBottomLeft="true"
        fresco:roundBottomRight="true"
        fresco:roundTopLeft="true"
        fresco:roundTopRight="true"
        fresco:roundedCornerRadius="50dp"
        fresco:roundingBorderColor="@color/red"
        fresco:roundingBorderWidth="2dp"
        fresco:retryImage="@drawable/retry"
        fresco:retryImageScaleType="centerCrop"
        fresco:actualImageScaleType="centerCrop"
        android:layout_below="@+id/tvTitle"
         />


    <!--for round image border use below-->

    <!--fresco:roundedCornerRadius="50dp"-->
    <!--fresco:roundTopLeft="true"-->
    <!--fresco:roundTopRight="true"-->
    <!--fresco:roundBottomLeft="true"-->
    <!--fresco:roundBottomRight="true"-->


</RelativeLayout>
MPelletier
  • 16,256
  • 15
  • 86
  • 137
Mohd Sakib Syed
  • 1,679
  • 1
  • 25
  • 42

1 Answers1

2

@Sakib Syed you can try to this code hope this can help you.

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    imagePipeline.clearMemoryCaches();
    imagePipeline.clearDiskCaches();

// combines above two lines

    imagePipeline.clearCaches();
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26