Prevent crash

This commit is contained in:
M66B 2019-03-25 19:20:23 +00:00
parent 6ed02843df
commit e0db116401
2 changed files with 8 additions and 2 deletions

View File

@ -69,6 +69,7 @@ public class ServiceTileUnseen extends TileService {
@Override @Override
public void onDestroy() { public void onDestroy() {
owner.destroy();
super.onDestroy(); super.onDestroy();
} }

View File

@ -19,7 +19,7 @@ public class TwoStateOwner implements LifecycleOwner {
owner.getLifecycle().addObserver(new LifecycleObserver() { owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() { public void onDestroyed() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); destroy();
} }
}); });
} }
@ -33,10 +33,15 @@ public class TwoStateOwner implements LifecycleOwner {
} }
void restart() { void restart() {
registry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); stop();
start(); start();
} }
void destroy() {
if (!registry.getCurrentState().equals(Lifecycle.State.DESTROYED))
registry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
}
@NonNull @NonNull
@Override @Override
public Lifecycle getLifecycle() { public Lifecycle getLifecycle() {