[TIMOB-25656] Android. TiViewProxy.getOrCreateView returns null on Titanium 7.0.0+
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-01-25T16:22:35.000+0000 |
Affected Version/s | Release 7.0.0 |
Fix Version/s | Release 7.0.2 |
Components | Android |
Labels | Android, development, module |
Reporter | Sergey Volkov |
Assignee | Gary Mathews |
Created | 2018-01-09T11:16:35.000+0000 |
Updated | 2018-01-26T19:11:27.000+0000 |
Description
Before 7.0.0 "TiViewProxy.getOrCreateView()" never returned "null". Now it does.
[Breaking commit](https://github.com/appcelerator/titanium_mobile/commit/58ffbd5147faa90259d805957ab8957c7a84b912#diff-bec22e2efdd8b352a7754ea42f435dc7R487)
In attached example I use DrawerLayout, but problem can appear in every module which use "getOrCreateView()" without checking result for "null".
Attachments
File | Date | Size |
---|---|---|
-.txt | 2018-01-09T11:24:08.000+0000 | 8272 |
app.js | 2018-01-09T11:09:10.000+0000 | 1981 |
[^-.txt] From https://ti-slack.slack.com/files/U06V3AS8Y/F8LPGH1KQ/-.txt
Hey [~s.volkov], thanks for reporting! 7.0.0 was a major release with many breaking changes as described in [semantic versioning](https://semver.org/). Anyway, I don't think this was planned, so I'll move the ticket to have it investigated by the Android team to provide you an alternative. Thanks!
[~s.volkov], this was done on purpose. It'll only return null if the parent activity was destroyed or was never assigned. This is typically the case when the proxy's view has been released after its parent activity has been destroyed (via the back-button). Once the activity has been destroyed, we cannot create another view since the activity context has been destroyed or else this will lead to other problems (ie: where it's crashing now used to be using destroyed activity contexts). The real issue here is there are place in the code that is missing null checks after an activity has been destroyed. Particularly in handleMessage() method calls which can get invoked by a view/activity/proxy after all UI elements have been released (not a Titanium issue; this is how it works for all native Android developers). Thanks for the stack-trace. We'll use that to fix that specific issue.
In example I create proxies while _win2_ is opened, but I don't attach them to _win2_, so no views really created. After _win2_ is closed and this proxies become useless, because activity from _win2_ is destroyed. Maybe we should not assign activity to proxy, before its view created (and use TiApplication.getCurrentActivity() while actual activity not assigned)? P.S. This issue was opened after [this](https://github.com/manumaticx/Ti.DrawerLayout/issues/88) in original Ti.DrawerLayout module.
To be clear, [stack trace (-.txt)|^-.txt] is not from [example (app.js) | ^app.js] .
[~s.volkov], The specific issue here is that the proxy was created and assigned win2's activity (because it was the top-most activity at the time), but the proxy wasn't used and attempted to create its view until after win'2 activity was destroyed (which it still references). Before our code change, it would have created its view based on the destroyed activity, which you can do but there is a high risk of running into illegal-state exceptions. We'll look into an alternative solution. For now, you can work-around this by creating these views at launch. This will work because the root activity which shows the splash screen exists for the lifetime of the JavaScript runtime. Alternatively, create these views during the window's "open" event for the window they're intended to be displayed in (less convenient to code, but it'll work).
master: https://github.com/appcelerator/titanium_mobile/pull/9721
[~gmathews], Can you please provide a backport.
-FR Passed for master. Waiting for merge to get enabled.- Found some issues.
7_0_X: https://github.com/appcelerator/titanium_mobile/pull/9743
Found issues in Backport.
FR passed for backport. Waiting for merge to become enabled.
Backport PR merged.
Master PR merged.
Verified the fix with SDK 7.1.0.v20180125082515 & 7.1.0.v20180125082515. Closing. Studio Ver: 5.0.0.201712081732 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.11 Appc CLI: 7.0.1 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.10.10 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ samsung SM-G955U1 --- Android 7.0 ⇨ google Nexus 5 --- Android 6.0.1 Emulator: android 8.0