LifecycleObserver - Check if observer has another owner

Viewed 1583

I have a class which I attached an observer to in the constructor:

public class MyStateMgr implements LifecycleObserver {

     public MyStateMgr (LifecycleOwner lifecycleOwner) {
            lifecycleOwner.getLifecycle().addObserver(this);
    }
}

The problem is that I get IllegalArgumentException. I checked about this crash and I saw that "If the observer is already in the list with another owner, LiveData throws an IllegalArgumentException."

I call this constructor only once. How can I check if this observer has another owner? Is there a way to check it? Maybe it's another reason?

This is the crash:

Fatal Exception: java.lang.IllegalArgumentException
       at android.arch.lifecycle.LifecycleRegistry.downEvent(LifecycleRegistry.java:255)
       at android.arch.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:306)
       at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:327)
       at android.arch.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:188)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:172)
       at android.os.HandlerThread.run(HandlerThread.java:65)
0 Answers
Related