I am using picasso to load image from a url. Since i needed bitmap for further processing, I am using Target() class for saving the bitmap. But picasso is not loading the image on the first run. But it loads at the time when i goes to another activity and getting back to the picasso implemented activity. Why it is happening ? Any fixes? My code is below,
Picasso.with(getActivity()).load(card.getExtras().getImageUrl()).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date now = new Date();
filename ="certificate_"+ formatter.format(now) + ".png";
File path=null;
if (getActivity().getExternalCacheDir()==null) {
path=getActivity().getCacheDir();
}
if(getActivity().getExternalCacheDir()!=null){
path=getActivity().getExternalCacheDir();
}
File image=new File(path+filename);
FileOutputStream fileOutPutStream = null;
try {
fileOutPutStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream);
fileOutPutStream.flush();
fileOutPutStream.close();
Log.d("---REACHED","FILE SAVED--------------");
} catch (Exception e) {
Crashlytics.logException(e);
}