Commit c607e03
committed
Fix multi-child ViewRenderer NPE when removing Android Views on Activity cleanup.
With features such as a backstack that may render multiple children under a parent view, we are seeing crashes like this on activity destruction:
```
java.lang.RuntimeException: Unable to destroy activity {software.amazon.app.platform.demo/software.amazon.app.platform.recipes.FeatureActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.dispatchDetachedFromWindow()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6269)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:6301)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:52)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63)
at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:169)
at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:101)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
```
This happens in any instance where there are multiple child views under a parent ViewGroup, and the hosting Activity is destroyed. We manually remove children from the parent, but this mutates the child sequence within the parent and results in an NPE when Android tries to do cleanup on its end. Adjust the child view removal logic to run on the main thread sequentially after any cleanup Android does.1 parent d787ad9 commit c607e03
File tree
1 file changed
+9
-3
lines changed- renderer-android-view/public/src/androidMain/kotlin/software/amazon/app/platform/renderer
1 file changed
+9
-3
lines changedLines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
149 | | - | |
150 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
151 | 157 | | |
152 | 158 | | |
153 | 159 | | |
| |||
0 commit comments