You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to save an image with Picasso, i have the web url of the image, and i also have a specific filename for it. I tried to pass the .into() method to a Target which will save the image for me but the onBitmapLoaded Method is never called. Here is my code...
This above i call for the image download, Context is clear what it is, String url is the web url of the image and String filename is the File name i want to give the file in the Target run method later...
privatestaticTargetgetTarget(finalStringfileName){Targettarget=newTarget(){
@OverridepublicvoidonBitmapLoaded(finalBitmapbitmap,finalPicasso.LoadedFromfrom){newThread(newRunnable(){
@Overridepublicvoidrun(){if(!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){Log.i(TAG,"The SD Card is not Mounted");}else{Filefile=newFile(getFileName(fileName));try{FileOutputStreamostream=newFileOutputStream(file);bitmap.compress(Bitmap.CompressFormat.JPEG,100,ostream);ostream.close();}catch(Exceptione){e.printStackTrace();Log.e(TAG,e.getMessage());}}}}).start();}
@OverridepublicvoidonBitmapFailed(DrawableerrorDrawable){}
@OverridepublicvoidonPrepareLoad(DrawableplaceHolderDrawable){}};returntarget;}
And this is the method of obtaining the filename...
You are not retaining a strong reference to the Target and so it is being garbage collected. Picasso does not hold a strong reference to any target (be it a Target or ImageView, etc.). You need to store the Target somewhere so that it won't be collected. In this case there's not enough code to know who the caller of the method is, but usually they are the person which should be holding on to the reference in a field or something.
In general, though, is #506. And since you're not actually using Picasso to manipulate the image, I would recommend using your HTTP client (like OkHttp) directly to download the file as you can skip the needless decoding step and thread hopping and stream the bytes directly to disk.
I am trying to save an image with Picasso, i have the web url of the image, and i also have a specific filename for it. I tried to pass the .into() method to a Target which will save the image for me but the onBitmapLoaded Method is never called. Here is my code...
This above i call for the image download, Context is clear what it is, String url is the web url of the image and String filename is the File name i want to give the file in the Target run method later...
And this is the method of obtaining the filename...
Why the onBitmapLoaded is never called?! Any clue?
The text was updated successfully, but these errors were encountered: