0

In my app I had used the picasso library but when I integrated in my code then it will show .invalidate(file) by red color . How can solve it?

Please find the below code for more reference:

        FutureCallback<File> writeNewFileCallback = new FutureCallback<File>() {
        @Override
        public void onCompleted(Exception e, File file) {
            if (e == null) { // Success


                Picasso.with(MyApp.this.getActivity()).invalidate(file);


                Transformation transformation = new     RoundedTransformationBuilder()
                        .scaleType(ImageView.ScaleType.FIT_XY)
                        .borderColor(Color.parseColor("#77e5e5e5"))
                        .borderWidthDp(2)
                        .cornerRadiusDp(15)
                        .oval(false)
                        .build();}

When change it to :

`Picasso.with(this).invalidate(file);`

"this" will be unknown.

Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51
AndroidDev
  • 701
  • 3
  • 9
  • 21

2 Answers2

0

For user interface related calls use the Activity context.

See this explanation by Reto Meier: Using Application context everywhere?

Community
  • 1
  • 1
Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77
0

This is simple to solve. Just do,

Picasso.with(getApplicationContext()).invalidate(file);

The with() method takes a Context as parameter, putting this works fine when you are inside an Activity.

But in your case, you are using this inside an anonymous inner class, so this refers to that specific class and not your Context.

Hope it helps.

Aritra Roy
  • 15,355
  • 10
  • 73
  • 107