Browse Source

test 13 fix

devab
MTing 4 weeks ago
parent
commit
0094e4e474
  1. 14
      app/src/main/java/com/ouxuan/oxface/utils/MaintenanceScheduler.java
  2. 27
      app/src/main/java/com/ouxuan/oxface/utils/MemoryManager.java

14
app/src/main/java/com/ouxuan/oxface/utils/MaintenanceScheduler.java

@ -312,8 +312,19 @@ public class MaintenanceScheduler {
MemoryManager memoryManager = MemoryManager.getInstance(context); MemoryManager memoryManager = MemoryManager.getInstance(context);
memoryManager.performMemoryCleanup(); memoryManager.performMemoryCleanup();
// 清理Glide缓存
// 清理Glide缓存 - 必须在主线程中执行
if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) {
// 当前在主线程直接执行
Glide.get(context).clearMemory(); 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();
}
});
}
Log.d(TAG, "内存清理完成"); Log.d(TAG, "内存清理完成");
} }
@ -375,6 +386,7 @@ public class MaintenanceScheduler {
@Override @Override
public void run() { public void run() {
try { try {
// 磁盘缓存清理必须在后台线程执行
Glide.get(context).clearDiskCache(); Glide.get(context).clearDiskCache();
Log.i(TAG, "磁盘缓存清理完成"); Log.i(TAG, "磁盘缓存清理完成");
} catch (Exception e) { } catch (Exception e) {

27
app/src/main/java/com/ouxuan/oxface/utils/MemoryManager.java

@ -114,10 +114,22 @@ public class MemoryManager {
try { try {
Log.i(TAG, "开始内存清理"); Log.i(TAG, "开始内存清理");
// 清理Glide图片缓存
// 清理Glide图片缓存 - 必须在主线程中执行
if (context != null) { if (context != null) {
if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) {
// 当前在主线程直接执行
Glide.get(context).clearMemory(); Glide.get(context).clearMemory();
Log.d(TAG, "已清理Glide内存缓存"); 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) { if (context != null) {
// 清理Glide内存缓存 - 必须在主线程中执行
if (android.os.Looper.myLooper() == android.os.Looper.getMainLooper()) {
// 当前在主线程直接执行
Glide.get(context).clearMemory(); 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() { new Thread(new Runnable() {
@Override @Override

Loading…
Cancel
Save