Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27085] Android: Close event not fired when close() called immediately after open()

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionWon't Fix
Resolution Date2019-05-20T09:03:19.000+0000
Affected Version/sRelease 7.5.0, Release 8.0.1
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterJan Vennemann
AssigneeUnknown
Created2019-05-17T11:36:58.000+0000
Updated2019-05-20T09:03:19.000+0000

Description

When calling close() immediately after open() Android and iOS fire different events. I noticed this while working with our unit test suite where this happens frequently. *Steps to reproduce the behavior*

Run the following code in a classic app

const win = Ti.UI.createWindow();
win.addEventListener('close', () => {
  console.log('close');
});
win.addEventListener('open', () => {
  console.log('open');
});
win.open();
win.close();
*Actual behavior* On iOS both events are fired. On Android the behavior varies depending on the SDK version. * 8.0.0.GA and before: Only the open event will be fired * 8.0.1.GA+: No event will be fired at all *Expected behavior* Not sure what should be the right behavior here in terms of what events to fire, but iOS and Android should fire the same events.

Comments

  1. Joshua Quick 2019-05-17

    [~jvennemann], this is technically the correct native behavior on Android. We can't directly open/create an Android Activity. We request the Android OS to do it for us via a call to the Java startActivity() method. This means it won't open immediately. We used to have a bug where if you open and close a window back-to-back like you are doing, it wouldn't close. The window would stay open (you would see this issue in our mocha test suite as well). This issue was resolved in 8.0.1 via [TIMOB-26996]. But basically what this means is if you open/close a window like this, it'll never be natively opened and the events won't fire. I would say this is the correct behavior. Especially since the "open" event would be useless since there is no native activity window to work with and I know app devs like to manipulate the ActionBar via the "open" event (they can't in this case).
  2. Jan Vennemann 2019-05-20

    Thanks for the clarification, Josh. I kinda was expecting that this is the correct behavior on Android so i didn't define the expected behavior in the ticket description. I'll close this ticket and will revisit our mocha test suite then. We have a lot of test cases where we just open the window at the end of a test and immediately close in the afterEach hook. Sometimes this will cause timeouts because close() will be called before the window has finished opening and no close event will be fired (which is used to finish the afterEach hook).

JSON Source