我有一个在构造函数中附加了观察者的类:
public class BIBOStateMgr implements LifecycleObserver {
public BIBOStateMgr (LifecycleOwner lifecycleOwner) {
lifecycleOwner.getLifecycle().addObserver(this);
}
}
问题是我得到了IllegalArgumentException。我检查了这次崩溃,发现“如果观察者已经在列表中并且与另一个所有者在一起,LiveData会抛出IllegalArgumentException。”
我只调用一次此构造函数。 如何检查该观察者是否还有其他所有者?有没有办法检查它?也许是另一个原因?
这是崩溃:
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 co.hopon.bibosdk.core.BIBOStateMgr.<init>(BIBOStateMgr.java:111)
at co.hopon.bibosdk.BIBOService$1.run(BIBOService.java:206)
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)