Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1327] Android: Alloy not working well when activity recreated by system

GitHub Issuen/a
TypeBug
PriorityCritical
StatusReopened
ResolutionUnresolved
Affected Version/sRelease 5.2.0
Fix Version/sn/a
ComponentsModels
Labelsn/a
ReporterShawn Lan
AssigneeFeon Sua Xin Miao
Created2015-08-20T23:56:47.000+0000
Updated2019-04-04T01:13:43.000+0000

Description

Refer to "don't keep activities option" [here](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Activity) So I test it with my app written in Alloy. Several issues. For example, action bar menu items are gone if the menu is defined only in Alloy markup. With Titanium Class, it seems fine. Usually people won't turn on "Don't keep activities," but it's available under developer's options for us to simulate the scenario when the system destroys (due to low memory) and recreates our activities. I believe the problem is with Alloy. I just list one example issue. Please investigate. Test cases: Classic
var win = Ti.UI.createWindow({
  fullscreen: true
});

var activity = win.activity;

activity.onCreateOptionsMenu = function(e){
  var menu = e.menu;
  var menuItem = menu.add({
    title: "Item 1",
    icon:  "item1.png",
    showAsAction: Ti.Android.SHOW_AS_ACTION_IF_ROOM
  });
  menuItem.addEventListener("click", function(e) {
    Ti.API.debug("I was clicked");
  });
};

win.open();
Alloy index.js
function doClick(e) {
    Ti.API.info("Menu item clicked: " + e.source.title);
}

// Ensure menu is displayed
function doOpen(e) {
    $.win.invalidateOptionsMenu();
}
index.xml
<Alloy>
    <!-- Create a heavyweight window to use the Android menu. -->
    <Window id="win" fullscreen="true" onOpen="doOpen">

        <!-- The Menu tag adds the Android menu. -->
        <Menu id="menu" platform="android">

            <!-- Cannot specify node text.  Use attributes only. -->
            <MenuItem id="menuItem" title="Item 1" icon="item1.png" onClick="doClick" showAsAction="Ti.Android.SHOW_AS_ACTION_IF_ROOM" />
        </Menu>

        <!-- Place additional views here -->
    </Window>
</Alloy>

Attachments

FileDateSize
Screen Shot 2016-01-07 at 6.21.33 PM.png2016-01-08T02:30:46.000+000078010
Screen Shot 2016-01-07 at 6.22.21 PM.png2016-01-08T02:30:46.000+000062029

Comments

  1. Shawn Lan 2015-10-02

    Like I said, there are several issues, but the root cause is the same. Use the menu sample as a start. See my updated description. Thanks.
  2. Feon Sua Xin Miao 2015-11-12

    I'm not able to reproduce the reported issue. Also, the test app index.js should be updated as follows:
       $.win.invalidateOptionsMenu(); // should be --> $.win.activity.invalidateOptionsMenu();
       
  3. Shawn Lan 2016-01-08

    Can you please share with me how to test it? The issue is there, at least from my test. Thanks.
  4. Feon Sua Xin Miao 2016-01-08

    Reopen to upload screenshots
  5. Feon Sua Xin Miao 2016-01-08

    [~shawnlan], attached are what I get running the alloy test app you provided. Please let me know if I have overlooked anything.
  6. Shawn Lan 2016-01-08

    To test "Do Not Keep Activities:" after launching the app, press "Home" (not Back) to put the app into background. Then bring the app to the foreground from launcher. See if this time the menu item is gone. Make sure you are using the Alloy example, not the Classic example. Thanks!
  7. Feon Sua Xin Miao 2016-01-08

    [~shawnlan], thanks for the clarification, I'll look into!

JSON Source