[ALOY-1327] Android: Alloy not working well when activity recreated by system
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Reopened |
Resolution | Unresolved |
Affected Version/s | Release 5.2.0 |
Fix Version/s | n/a |
Components | Models |
Labels | n/a |
Reporter | Shawn Lan |
Assignee | Feon Sua Xin Miao |
Created | 2015-08-20T23:56:47.000+0000 |
Updated | 2019-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
File | Date | Size |
---|---|---|
Screen Shot 2016-01-07 at 6.21.33 PM.png | 2016-01-08T02:30:46.000+0000 | 78010 |
Screen Shot 2016-01-07 at 6.22.21 PM.png | 2016-01-08T02:30:46.000+0000 | 62029 |
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.
I'm not able to reproduce the reported issue. Also, the test app
index.js
should be updated as follows:Can you please share with me how to test it? The issue is there, at least from my test. Thanks.
Reopen to upload screenshots
[~shawnlan], attached are what I get running the alloy test app you provided. Please let me know if I have overlooked anything.
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!
[~shawnlan], thanks for the clarification, I'll look into!