mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-29 09:01:30 +01:00
Added lifecycle logging
This commit is contained in:
@@ -8,20 +8,33 @@ import androidx.lifecycle.LifecycleRegistry;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
public class TwoStateOwner implements LifecycleOwner {
|
||||
private String name;
|
||||
private LifecycleRegistry registry;
|
||||
|
||||
// https://developer.android.com/topic/libraries/architecture/lifecycle#lc
|
||||
|
||||
TwoStateOwner() {
|
||||
TwoStateOwner(String aname) {
|
||||
name = aname;
|
||||
|
||||
registry = new LifecycleRegistry(this);
|
||||
registry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
||||
|
||||
registry.addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
public void onAny() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.i("LifeCycle " + name + " state=" + registry.getCurrentState());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TwoStateOwner(LifecycleOwner owner) {
|
||||
this();
|
||||
TwoStateOwner(LifecycleOwner owner, String aname) {
|
||||
this(aname);
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroyed() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.i("LifeCycle " + name + " parent destroyed");
|
||||
destroy();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user