[AC-6216] Android: Issue after a long time of inactivity
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2019-04-19T22:33:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | TabGroup, android |
Reporter | Rainer Schleevoigt |
Assignee | Shak Hossain |
Created | 2019-04-19T09:06:13.000+0000 |
Updated | 2019-04-19T22:33:39.000+0000 |
Description
The new versions of Android kills apps after long time of sleeping. The requesting of BatterySafingPermission doesn't help for all devices. ;-(
My observation:
if I restart the app after waking up from sleeping mode then the app seems to frozen.
Here the tracelog: https://gist.github.com/AppWerft/59ca215fb603f5a29394f7fb07b00227
Here my samplecode:
// root activity called by app.js:
module.exports = function() {
const $ = Ti.UI.createTabGroup({
fullscreen : false,
exitOnClose : true,
orientationModes : [ Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT ]
});
$.addEventListener('open', require('ui/common/main.menu'));
$.open();
};
And here the menu, calling after opening of tabgroup:
// main.menu.js:
module.exports = function() {
const lifecyclecontainer = arguments[0].source;
console.log("_openevent");
if (!lifecyclecontainer)
return;
var activity = lifecyclecontainer.getActivity();
if (activity) {
console.log("_openevent activity"); // last seen message!!!
activity.onCreateOptionsMenu = function(_menu) {
console.log("_openevent onCreateOptionsMenu");
const menuItem = _menu.menu.add({
icon : Ti.App.Android.R.drawable.ic_action_audio,
showAsAction : Ti.Android.SHOW_AS_ACTION_IF_ROOM,
});
};
activity.invalidateOptionsMenu();
}
};
Summary: the activity of tabgroup is != null, but the next statement activity.onCreateOptionsMenu
thows an exception. The code runs on first start of app, but crashes after resuming. This issue only appears with new SDK >=7 and >=Oreo.
Timing issue?
With the "Don't keep activities" on in developer options I can trigger the crash immediately: Steps: 1. Running app 2. Back button 3. Restart from Home screen => no issue 1. Running app 2. Menu button or screen off 3. Restart 4. Crash with log above
[~titanium@webmasterei-hamburg.de], this is a known issue which is reported here: [TIMOB-26964] This issue is scheduled to be resolved in Titanium 8.0.1. I tested the below Classic app code with that ticket's PR and have confirmed that it'll fix your issue. It displays a menu item like how you're doing it and it's definitely recreating the menu item when the activity window is being "restored" by the Android OS (ie: after resuming the app).
Please note that this is known to crash in Titanium 7.2.1 through 7.5.1. In Titanium 8.0.0, the
TabGroup
appears empty instead and doesn't crash. Still not great, but at least the crash is gone. In 8.0.1, it'll work as expected.