Android 学习笔记

Thread 线程中显示 Toast

1
2
3
4
5
XXActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(XXActivity.this, "下载成功", Toast.LENGTH_SHORT).show();
}
});

Glide 下载图片 保存到SD卡

Glide save image file to sd card

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Glide.with(this)
.load(url)
.asBitmap()
.skipMemoryCache(true)
.into(new SimpleTarget<Bitmap>(1080, 1920) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
String fileName = "image.jpg";
final File file = new File("/storage/sdcard1/Pictures/" + fileName );
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
GirlDetailActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(GirlDetailActivity.this, "下载成功", ""), Toast.LENGTH_SHORT).show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});