Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2220] Android: displayHomeAsUp and onCreateOptionsMenu together are broken

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2014-01-19T08:07:27.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsactionbar, android
ReporterThomas Keunebroek
AssigneeShak Hossain
Created2013-01-14T08:23:09.000+0000
Updated2016-03-08T07:41:13.000+0000

Description

When you open a heavyweight Window from a TabGroup's tab and set the new window's Activity's ActionBar's displayHomeAsUp property to true, the Activity.onCreateOptionsMenu() callback is never called, therefore the menu items are not created. Code snippet:
var win = Ti.UI.createWindow({
   title: 'New win',
   backgroundColor: 'white'
});
var activity = win.getActivity();
win.addEventListener('open', function() {
   activity.actionBar.setDisplayHomeAsUp(true);
});
activity.onCreateOptionsMenu = function(e) {
   var menu = e.menu;
   menu.add({
     title: 'Your action',
     showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
   });
};

yourTab.open(win);
If we remove the line that sets displayHomeAsUp to true, the menuItem is correctly drawn.

Comments

  1. Nikhil Sharma 2013-02-06

    The test case that you've provided contains errors. Could you please provide a valid test case?
  2. Thomas Keunebroek 2013-02-06

    Here you go: app.js
       (function() {
       
           var tabGroup = Ti.UI.createTabGroup();
       
       	var win1 = Ti.UI.createWindow({
               title: 'win1'
           });
       
           var btn = Ti.UI.createButton({
               title: 'open win2',
               height: 84,
               width: 200,
               top: 20
           });
       
           win1.add(btn);
       
           var win2 = Ti.UI.createWindow({
               title: 'win2'
           });
       
           btn.addEventListener('click', function() {
               tab.open(win2);
           });
       
           win2.addEventListener('open', function() {
               this.getActivity().actionBar.setDisplayHomeAsUp(true);
           });
       
           win2.getActivity().onCreateOptionsMenu = function(e) {
               var menu = e.menu;
               menu.add({
                   title: 'My action',
                   showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
               });
           };
       
           var tab = Ti.UI.createTab({
               title: 'tab',
               window: win1
           });
       
           tabGroup.addTab(tab);
       
           tabGroup.open();
       
       })();
       
    tiapp.xml
       <?xml version="1.0" encoding="UTF-8"?>
       <ti:app xmlns:ti="http://ti.appcelerator.org">
           <id>com.tab.test</id>
           <name>TabTest</name>
           <version>1.0</version>
           <publisher>shopmium</publisher>
           <url>http://</url>
           <description>not specified</description>
           <copyright>2013 by shopmium</copyright>
           <icon>appicon.png</icon>
           <persistent-wifi>false</persistent-wifi>
           <prerendered-icon>false</prerendered-icon>
           <statusbar-style>default</statusbar-style>
           <statusbar-hidden>false</statusbar-hidden>
           <fullscreen>false</fullscreen>
           <navbar-hidden>false</navbar-hidden>
           <analytics>true</analytics>
           <guid>e962583e-41b2-4280-b05a-dfa612e015f2</guid>
           <property name="ti.ui.defaultunit" type="string">system</property>
           <iphone>
               <orientations device="iphone">
                   <orientation>Ti.UI.PORTRAIT</orientation>
               </orientations>
               <orientations device="ipad">
                   <orientation>Ti.UI.PORTRAIT</orientation>
                   <orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
                   <orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
                   <orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
               </orientations>
           </iphone>
       	<android xmlns:android="http://schemas.android.com/apk/res/android">
       	<tool-api-level>17</tool-api-level>
       	<manifest>
       		<uses-sdk android:minSdkVersion="8" />
       	
       		<!-- TI_MANIFEST -->
       	
       		<application android:icon="@drawable/appicon"
       			android:label="TabTest" android:name="TabtestApplication"
       			android:theme="@android:style/Theme.Holo.Light"
       			android:debuggable="false">
       	
       			<!-- TI_APPLICATION -->
       	
       			<activity android:name=".TabtestActivity"
       				android:label="TabTest"
       				android:configChanges="keyboardHidden|orientation">
       				<intent-filter>
       					<action android:name="android.intent.action.MAIN" />
       					<category android:name="android.intent.category.LAUNCHER" />
       				</intent-filter>
       			</activity>
       	
       			<activity android:name="org.appcelerator.titanium.TiActivity"
       				android:configChanges="keyboardHidden|orientation" />
       			<activity android:name="org.appcelerator.titanium.TiTranslucentActivity"
       				android:configChanges="keyboardHidden|orientation"
       				android:theme="@android:style/Theme.Translucent" />
       			<activity android:name="org.appcelerator.titanium.TiModalActivity"
       				android:configChanges="keyboardHidden|orientation"
       				android:theme="@android:style/Theme.Translucent" />
       			<activity android:name="ti.modules.titanium.ui.TiTabActivity"
       				android:configChanges="keyboardHidden|orientation" />		
       	
       		</application>	
       	
       		</manifest>
       	</android>
           <modules/>
           <deployment-targets>
               <target device="blackberry">false</target>
               <target device="android">true</target>
               <target device="ipad">false</target>
               <target device="iphone">false</target>
               <target device="mobileweb">false</target>
           </deployment-targets>
           <sdk-version>3.0.0.GA</sdk-version>
       </ti:app>
       
    If you run the above code snippet, you'll see that you don't have any options menu created. However, if you don't set the up affordance by commenting the line
    this.getActivity().actionBar.setDisplayHomeAsUp(true)
    , you will get your action. Those two features should be working at the same time without any problem. I hope it's clearer this way. Regards,
  3. Mostafizur Rahman 2013-12-07

    Hello, We tested this issue with your test code using the latest 3.1.3 GA. We can’t reproduce this issue in Ti SDK 3.1.3GA. It is most likely fixed. Please test your issue using the latest release and let us know your feedback.

    Testing Environment:

    OS: MAC OS X 10.8.5 Ti SDK: 3.0.0/3.1.3GA Android SDK 4.2.2 Thanks

JSON Source