Commit a6ca6be
committed
Fix activity recreation crashes with tabs and complex view hierarchies
When "Don't keep activities" is enabled (or the system destroys the activity
to reclaim memory), NativeScript apps using ViewPager2-based tabs (e.g.
@nativescript-community/ui-material-tabs) crash on foregrounding.
Two root causes are addressed:
1. ActionBar's disposeNativeView() nulled _actionItems, causing
"Cannot read properties of null (reading 'addItem')" when the action bar
was recreated during _setupUI after activity destruction.
2. Android's FragmentManager restores all fragments from savedInstanceState
during super.onCreate(), including third-party fragments (ViewPager2's
f0, f1, etc.). NativeScript's _tearDownUI/_setupUI cycle rebuilds the
entire view tree from scratch, leaving these restored fragments orphaned
— they reference container views that no longer exist, causing "Fragment
does not have a view" errors. We now remove non-NativeScript fragments
immediately after super.onCreate() while preserving core's own fragments
(tagged fragment{id}[{depth}]) which have a proper restoration path via
_processNextNavigationEntry and FragmentCallbacksImplementation.onCreateView.1 parent 69dc869 commit a6ca6be
2 files changed
Lines changed: 27 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
861 | 861 | | |
862 | 862 | | |
863 | 863 | | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
864 | 891 | | |
865 | 892 | | |
866 | 893 | | |
| |||
0 commit comments