Skip to content

Commit 89d1611

Browse files
committed
fix(android): prevent crash on app going to background
1 parent 27bafd3 commit 89d1611

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/bottom-navigation/index.android.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,9 @@ export class BottomNavigation extends TabNavigationBase {
399399
super._onAttachedToWindow();
400400

401401
// _onAttachedToWindow called from OS again after it was detach
402-
// TODO: Consider testing and removing it when update to androidx.fragment:1.2.0
403-
if (this._manager && this._manager.isDestroyed()) {
402+
// still happens with androidx.fragment:1.3.2
403+
const activity = Application.android.foregroundActivity;
404+
if ((this._manager && this._manager.isDestroyed()) || !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED)) {
404405
return;
405406
}
406407

src/tabs/tabs.android.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ export class Tabs extends TabsBase {
499499
super._onAttachedToWindow();
500500

501501
// _onAttachedToWindow called from OS again after it was detach
502-
// TODO: Consider testing and removing it when update to androidx.fragment:1.2.0
503-
if (this._manager && this._manager.isDestroyed()) {
502+
// still happens with androidx.fragment:1.3.2
503+
const activity = Application.android.foregroundActivity;
504+
if ((this._manager && this._manager.isDestroyed()) || !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED)) {
504505
return;
505506
}
506507

0 commit comments

Comments
 (0)