0

I am trying to implement LifecycleObserver on a custom RelativeLayout View. I am able to get the ON_RESUME event but for some reason the ON_PAUSE or ON_DESTROY event doesn't get triggered.

public class MyView extends RelativeLayout implements View.OnTouchListener, LifecycleObserver {

       public MyView (Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        setOnTouchListener(this); 
        ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onViewPause()
    {
        Log.e("ON_PAUSE","ON_PAUSE");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onViewResume()
    {
        Log.e("ON_RESUME","ON_RESUME");
    }
}

What am I missing?

4

0 回答 0