diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 90876532b4..52b910ff17 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -418,7 +418,7 @@ public class AdapterAccount extends RecyclerView.Adapter { } @Override - public void onViewRecycled(@NonNull ViewHolder holder) { + public void onViewDetachedFromWindow(@NonNull ViewHolder holder) { holder.powner.recreate(); } } diff --git a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java index e026c9fdf4..07f928d8f5 100644 --- a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java +++ b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java @@ -30,24 +30,12 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver { - private LifecycleOwner owner; public PopupMenuLifecycle(@NonNull Context context, LifecycleOwner owner, @NonNull View anchor) { super(context, anchor); - this.owner = owner; Log.i("Instantiate " + this); - anchor.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { - @Override - public void onViewAttachedToWindow(View v) { - // Do nothing - } - - @Override - public void onViewDetachedFromWindow(View v) { - PopupMenuLifecycle.this.dismiss(); - } - }); + owner.getLifecycle().addObserver(this); } @Override @@ -64,6 +52,5 @@ public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver { public void onDestroy() { Log.i("Destroy " + this); this.dismiss(); - owner = null; } }