|
|
@ -114,10 +114,22 @@ public class MemoryManager { |
|
|
|
try { |
|
|
|
Log.i(TAG, "开始内存清理"); |
|
|
|
|
|
|
|
// 清理Glide图片缓存 |
|
|
|
// 清理Glide图片缓存 - 必须在主线程中执行 |
|
|
|
if (context != null) { |
|
|
|
if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) { |
|
|
|
// 当前在主线程,直接执行 |
|
|
|
Glide.get(context).clearMemory(); |
|
|
|
Log.d(TAG, "已清理Glide内存缓存"); |
|
|
|
} else { |
|
|
|
// 当前不在主线程,使用Handler切换到主线程执行 |
|
|
|
new android.os.Handler(android.os.Looper.getMainLooper()).post(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
Glide.get(context).clearMemory(); |
|
|
|
Log.d(TAG, "已清理Glide内存缓存"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 建议垃圾回收 |
|
|
@ -141,7 +153,20 @@ public class MemoryManager { |
|
|
|
|
|
|
|
// 清理所有可能的缓存 |
|
|
|
if (context != null) { |
|
|
|
// 清理Glide内存缓存 - 必须在主线程中执行 |
|
|
|
if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) { |
|
|
|
// 当前在主线程,直接执行 |
|
|
|
Glide.get(context).clearMemory(); |
|
|
|
} else { |
|
|
|
// 当前不在主线程,使用Handler切换到主线程执行 |
|
|
|
new android.os.Handler(android.os.Looper.getMainLooper()).post(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
Glide.get(context).clearMemory(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 强制清理磁盘缓存(在后台线程中) |
|
|
|
new Thread(new Runnable() { |
|
|
|
@Override |
|
|
|