From 10aa8075ea6248ae9c2c7f3f7ca991e57601f705 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 28 Sep 2021 09:33:23 +0200 Subject: [PATCH] Auto clear views --- app/src/main/java/eu/faircode/email/ActivityBase.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index fe830c0a61..0cdc47a52e 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -60,6 +60,7 @@ import androidx.preference.PreferenceManager; import java.io.File; import java.io.FileOutputStream; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -763,6 +764,16 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc @Override public void onFragmentDestroyed(@NonNull FragmentManager fm, @NonNull Fragment f) { log(fm, f, "onFragmentDestroyed"); + try { + for (Field field : f.getClass().getDeclaredFields()) + if (View.class.isAssignableFrom(field.getType())) { + Log.i("Clearing " + f.getClass().getSimpleName() + ":" + field.getName()); + field.setAccessible(true); + field.set(f, null); + } + } catch (Throwable ex) { + Log.w(ex); + } } @Override