{ "id": "63394", "key": "TIMOB-2762", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11239", "name": "Release 1.6.0 M06", "archived": true, "released": true, "releaseDate": "2011-01-24" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T02:00:01.000+0000", "created": "2011-04-15T03:28:53.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "android", "defect", "enterprise", "release-1.6.0", "reported-1.6.0", "rplist" ], "versions": [], "issuelinks": [], "assignee": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-04-17T02:00:01.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{html}

Problem

\n

In the app.js,\n\"Titanium.Android.currentActivity.onCreateOptionsMenu = ...\" does\nnothing. Launching the app and pressing the menu button results in\nno menu popping up.

\n

Workaround

\n

Open a window with a URL set, and the nav bar hidden, modal\ntrue, or fullscreen true. In that JavaScript context, you can then\nproperly set the menu.

\n

Sample Code

\n

The following code, placed alone in an app.js, demonstrates the\nproblem. Launch the app and press the hardware Menu button to see\nthat nothing pops up.

\n
\n// add a menu.\nTitanium.Android.currentActivity.onCreateOptionsMenu = function (e) {\n    var menuItem = e.menu.add({ title: 'Window ' + i });\n    menuItem.setIcon('KS_nav_ui.png');\n    menuItem.addEventListener('click', function (e) {\n        alert('Clicked!');\n    });\n};\n// add some stuff to the window\nvar win = Titanium.UI.createWindow({\n    title: 'Window One',\n    backgroundColor: '#fff'\n});\nwin.add(Titanium.UI.createLabel({\n    color: '#999',\n    text: 'I am Window One',\n    font: { fontSize: 20, fontFamily: 'Helvetica Neue' },\n    textAlign: 'center',\n    width: 'auto'\n}));\nwin.open();\n
\n

My Guess at The Problem

\n

Perhaps Titanium.Android.currentActivity is not getting set in\napp.js.

\n

Associated Helpdesk Ticket

\n

Andreas Sandberg, an enterprise client, reported this issue.

{html}", "attachment": [], "flagged": false, "summary": "Android Ent Defect: Can't Add Menu to currentActivity In app.js", "creator": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "environment": null, "comment": { "comments": [ { "id": "129354", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

May not get schedule in as there is a simple workaround.

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:53.000+0000", "updated": "2011-04-15T03:28:53.000+0000" }, { "id": "129355", "author": { "name": "andreassandberg", "key": "andreassandberg", "displayName": "Andreas sandberg", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Hey Don, the workaround mentioned above does work but since we\nhave a fairly large code base already from our iphone\nimplementation it means that we have to register and fire global\nevents through Ti.App for the window opened with the menu\ndeceleration and the global context. About 95% of our code lives in\nthe global context and a large amount of data is shared between our\ntabs which can also contain about four different views per tab,\neach with a different menu need.

{html}", "updateAuthor": { "name": "andreassandberg", "key": "andreassandberg", "displayName": "Andreas sandberg", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:54.000+0000", "updated": "2011-04-15T03:28:54.000+0000" }, { "id": "129356", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Andreas. Thanks for the heads up. I try to get this in as soon\nas I can. Fixing the title adding the enterprise tag as well.

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:54.000+0000", "updated": "2011-04-15T03:28:54.000+0000" }, { "id": "129357", "author": { "name": "andreassandberg", "key": "andreassandberg", "displayName": "Andreas sandberg", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Many thanks Don. I took a look at TiRootActivity to see what was\nhappening with onCreateOptionsMenu compared to how the\nTiBaseActivity class is implemented. Looks like TiRootActivity acts\nas a boot loader of sort and is not tied into the global context.\nSince our app uses a tab group I noticed that there was a\nTiTabActivity class that was an actual activity and tried to again\nimplement the onCreateOptionsMenu method but no bueno. Thanks\nagain!

{html}", "updateAuthor": { "name": "andreassandberg", "key": "andreassandberg", "displayName": "Andreas sandberg", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:54.000+0000", "updated": "2011-04-15T03:28:54.000+0000" }, { "id": "129358", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Sample code has a bug. This may be used for testing.

\n
\n// add a menu.\nTitanium.Android.currentActivity.onCreateOptionsMenu = function (e) {\n    var menuItem = e.menu.add({ title: 'Window One' });\n    menuItem.setIcon('KS_nav_ui.png');\n    menuItem.addEventListener('click', function (e) {\n        alert('Clicked!');\n    });\n};\n// add some stuff to the window\nvar win = Titanium.UI.createWindow({\n    title: 'Window One',\n    backgroundColor: '#fff'\n});\nwin.add(Titanium.UI.createLabel({\n    color: '#999',\n    text: 'I am Window One',\n    font: { fontSize: 20, fontFamily: 'Helvetica Neue' },\n    textAlign: 'center',\n    width: 'auto'\n}));\nwin.open();\n
{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:55.000+0000", "updated": "2011-04-15T03:28:55.000+0000" }, { "id": "129359", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

(from [98b3a942bdee20383295b7e0aec14dcd9fe786c0])\n[#2762 state:fixed-in-qa] refactored menu code\ninto TiMenuSupport. Cleaned up a build error \nhttps://github.com/appcelerator/titanium_mobile/commit/98b3a942bdee...

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:55.000+0000", "updated": "2011-04-15T03:28:55.000+0000" }, { "id": "129360", "author": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

verified w/ Nexus S 2.3.2

{html}", "updateAuthor": { "name": "mculpepper", "key": "mculpepper", "displayName": "Marshall Culpepper", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:56.000+0000", "updated": "2011-04-15T03:28:56.000+0000" }, { "id": "129361", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

(from [a9eb1f6ede81d708cb0e8360c86483f6cd4839a4])\n[#2762] removed old menu support code that wasn't\nbeing used \nhttps://github.com/appcelerator/titanium_mobile/commit/a9eb1f6ede81...

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:28:56.000+0000", "updated": "2011-04-15T03:28:56.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }