我的代码有问题:
Picasso.with(getApplicationContext())
.load(postimage)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Android/data/myapps/cache/");
if (!myDir.exists()) {
myDir.mkdirs();
}
String name = new Date().toString() + ".jpg";
myDir = new File(myDir, filename);
FileOutputStream out = new FileOutputStream(myDir);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
Log.i("image", "Your image saved to :" + myDir);
out.flush();
out.close();
} catch (Exception e) {
// some action
}
}
我想从URL下载图像。该代码可以正常工作,但是它始终循环运行并且无法停止,即使已经下载也仍在下载。