Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2762] Android Ent Defect: Can't Add Menu to currentActivity In app.js

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:00:01.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M06
ComponentsAndroid
Labelsandroid, defect, enterprise, release-1.6.0, reported-1.6.0, rplist
ReporterDawson Toth
AssigneeDon Thorp
Created2011-04-15T03:28:53.000+0000
Updated2011-04-17T02:00:01.000+0000

Description

Problem

In the app.js, "Titanium.Android.currentActivity.onCreateOptionsMenu = ..." does nothing. Launching the app and pressing the menu button results in no menu popping up.

Workaround

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

Sample Code

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

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

My Guess at The Problem

Perhaps Titanium.Android.currentActivity is not getting set in app.js.

Associated Helpdesk Ticket

Andreas Sandberg, an enterprise client, reported this issue.

Comments

  1. Don Thorp 2011-04-15

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

  2. Andreas sandberg 2011-04-15

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

  3. Don Thorp 2011-04-15

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

  4. Andreas sandberg 2011-04-15

    Many thanks Don. I took a look at TiRootActivity to see what was happening with onCreateOptionsMenu compared to how the TiBaseActivity class is implemented. Looks like TiRootActivity acts as a boot loader of sort and is not tied into the global context. Since our app uses a tab group I noticed that there was a TiTabActivity class that was an actual activity and tried to again implement the onCreateOptionsMenu method but no bueno. Thanks again!

  5. Don Thorp 2011-04-15

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

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

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

  7. Marshall Culpepper 2011-04-15

    verified w/ Nexus S 2.3.2

  8. Don Thorp 2011-04-15

    (from [a9eb1f6ede81d708cb0e8360c86483f6cd4839a4]) [#2762] removed old menu support code that wasn't being used https://github.com/appcelerator/titanium_mobile/commit/a9eb1f6ede81d708cb0e8360c86483f6cd4839a4"> https://github.com/appcelerator/titanium_mobile/commit/a9eb1f6ede81...

JSON Source