fix(android): prevent possible crash when app goes to background

This commit is contained in:
Martin Guillon
2021-04-20 12:11:38 +02:00
parent 4019f001d3
commit d551693726

View File

@ -20,6 +20,7 @@ import { CSSUtils } from '../../css/system-classes';
import { Device } from '../../platform'; import { Device } from '../../platform';
import { profile } from '../../profiling'; import { profile } from '../../profiling';
import { ExpandedEntry } from './fragment.transitions.android'; import { ExpandedEntry } from './fragment.transitions.android';
import { android as androidApplication } from '../../application';
export * from './frame-common'; export * from './frame-common';
@ -146,8 +147,9 @@ export class Frame extends FrameBase {
super._onAttachedToWindow(); super._onAttachedToWindow();
// _onAttachedToWindow called from OS again after it was detach // _onAttachedToWindow called from OS again after it was detach
// TODO: Consider testing and removing it when update to androidx.fragment:1.2.0 // still happens with androidx.fragment:1.3.2
if (this._manager && this._manager.isDestroyed()) { const activity = androidApplication.foregroundActivity;
if ((this._manager && this._manager.isDestroyed()) || !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED)) {
return; return;
} }
@ -334,8 +336,6 @@ export class Frame extends FrameBase {
// If we had real navigation process queue. // If we had real navigation process queue.
this._processNavigationQueue(entry.resolvedPage); this._processNavigationQueue(entry.resolvedPage);
} else { } else {
// Otherwise currentPage was recreated so this wasn't real navigation. // Otherwise currentPage was recreated so this wasn't real navigation.
// Continue with next item in the queue. // Continue with next item in the queue.