mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
fix(android): prevent possible crash when app goes to background
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,11 +172,11 @@ export class Frame extends FrameBase {
|
|||||||
if (!this.isLoaded || this._executingContext) {
|
if (!this.isLoaded || this._executingContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case the activity is "reset" using resetRootView we must wait for
|
// in case the activity is "reset" using resetRootView we must wait for
|
||||||
// the attachedToWindow event to make the first navigation or it will crash
|
// the attachedToWindow event to make the first navigation or it will crash
|
||||||
// https://github.com/NativeScript/NativeScript/commit/9dd3e1a8076e5022e411f2f2eeba34aabc68d112
|
// https://github.com/NativeScript/NativeScript/commit/9dd3e1a8076e5022e411f2f2eeba34aabc68d112
|
||||||
// though we should not do it on app "start"
|
// though we should not do it on app "start"
|
||||||
// or it will create a "flash" to activity background color
|
// or it will create a "flash" to activity background color
|
||||||
if (this._wasReset && !this._attachedToWindow) {
|
if (this._wasReset && !this._attachedToWindow) {
|
||||||
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.
|
||||||
|
Reference in New Issue
Block a user