Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2368] Android: ActionBar not ready at window open event on API 18 (Android 4.3)

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2013-08-28T21:46:07.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labels3.1.1, 3.1.2, actionbar, android
ReporterMark Mokryn
AssigneeMauro Parra-Miranda
Created2013-08-21T17:02:10.000+0000
Updated2016-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

FileDateSize
upButtonBug.zip2013-08-21T17:02:10.000+000010317841

Comments

  1. Mark Mokryn 2013-08-21

    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.
  2. Mark Mokryn 2013-08-22

    If I hook on focus event instead of open - it works.
  3. Hieu Pham 2013-08-28

  4. Mark Mokryn 2013-08-29

  5. Mark Mokryn 2013-08-30

JSON Source