Prevent crash

pull/170/head
M66B 5 years ago
parent 3b1dded8c2
commit fec43eb51b

@ -20,9 +20,11 @@ package eu.faircode.email;
*/ */
import android.content.Context; import android.content.Context;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
@ -48,6 +50,22 @@ public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver {
} }
} }
@Override
public void setOnMenuItemClickListener(@Nullable OnMenuItemClickListener listener) {
super.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
// Handle click just before destroy
return listener.onMenuItemClick(item);
} catch (Throwable ex) {
Log.w(ex);
return false;
}
}
});
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() { public void onDestroy() {
Log.i("Destroy " + this); Log.i("Destroy " + this);

Loading…
Cancel
Save