[AC-2368] Android: ActionBar not ready at window open event on API 18 (Android 4.3)
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Closed |
| Resolution | Duplicate |
| Resolution Date | 2013-08-28T21:46:07.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Titanium SDK & CLI |
| Labels | 3.1.1, 3.1.2, actionbar, android |
| Reporter | Mark Mokryn |
| Assignee | Mauro Parra-Miranda |
| Created | 2013-08-21T17:02:10.000+0000 |
| Updated | 2016-03-08T07:41:23.000+0000 |
Description
Setting a handler for onHomeIconItemSelected on Android 4.3 has no effect - the home area is highlighted when clicked, but the handler doesn't trigger. This is not a regression of the Ti SDK, buggy on 3.1.1 too. Note that my tiapp.xml is within the specified Titanium compatibility matrix:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>17</tool-api-level>
<manifest android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16"/>
</manifest>
</android>
Test application attached.
Here is the faulting code:
*win2.xml*
<Alloy>
<Window id="win2" class="container" navBarHidden="false">
<Label text="Close me by clicking on up button"/>
</Window>
</Alloy>
*win2.js*
function closeMe() {
// this handler doesn't get called on Android 4.3
$.win2.close();
}
$.win2.addEventListener('open', function() {
if (OS_ANDROID) {
var activity = $.win2.getActivity();
var actionBar = activity.actionBar;
if (actionBar){
actionBar.title = 'Click to my left :)';
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = closeMe;
}
}
});
*index.xml*
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Click this label to open Window 2</Label>
</Window>
</Alloy>
*index.js*
function doClick(e) {
Alloy.createController('win2').getView().open();
}
$.index.open();
Attachments
| File | Date | Size |
|---|---|---|
| upButtonBug.zip | 2013-08-21T17:02:10.000+0000 | 10317841 |
It's a timing issue with getting activity.actionBar. If I wrap that with with a short timeout (i.e. setTimeout(function() {var actionBar = activity.actionBar;........ then the issue goes away. However - if I delay just the following ActionBar manipulation code the issue persists. BTW - I am now also seeing occasional crashes with ActionBar on API 18 (SDK 3.1.1.GA - not even bothering with 3.1.2.GA since it is much flakier) - "ActionBarImpl can only be used with a compatible window decor layout, source: var actionBar = activity.actionBar". Have never seen this with earlier API levels.
If I hook on focus event instead of open - it works.