由于LocalActivityManager已经过期官方停止维护,包含该成员变量的Activity存在泄漏风险,项目中如果使用到该类需在onDestroy时通过反射进行一次hack处理
System.gc();
Field activityManager = aClass.getDeclaredField("mLocalActivityManager");
activityManager.setAccessible(true);
LocalActivityManager manager = ((LocalActivityManager) activityManager.get(activity));
Field mResumed = manager.getClass().getDeclaredField("mResumed");
mResumed.setAccessible(true);
Object record = mResumed.get(manager);
Field window = record.getClass().getDeclaredField("window");
window.setAccessible(true);
Field activity1 = record.getClass().getDeclaredField("activity");
activity1.setAccessible(true);
window.set(record, null);
activity1.set(record, null);
activityManager.set(activity, null);
mResumed.set(manager, null);
Runtime.getRuntime().gc();
System.gc();