Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26746] Android: Ti.App wrongly fires pause/resume event when opening/closing child windows

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2019-03-26T11:03:17.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sRelease 8.0.1
ComponentsAndroid
Labelsandroid, app, engSchedule, event, parity, pause, resume
ReporterJoshua Quick
AssigneeJoshua Quick
Created2019-01-18T04:08:24.000+0000
Updated2019-03-26T11:03:17.000+0000

Description

*Summary:* Ti.App events "pause" and "paused" must only be fired when the app is put into the background. Events "resume" and "resumed" are to be fired when the app is returned to the foreground (include cold app startup). Android correctly does the above when put into the background and foreground. However, Android will also fire a "pause" and "resume" event when opening or closing a child window. This does not follow iOS' behavior and is a parity issue. *Note:* To be fair, the current pause/resume event behavior is how it natively works with Android's individual activities. However, app developers need these events to disable sensors when backgrounded and re-enable them when put back into the foreground, which is currently difficult to do in Titanium for the moment. *Steps to reproduce:*

Build and run the below code on Android.

Tap the "Open Child" button.

Observe the log.

Notice that pause and resume events were logged. _(This is the bug.)_

function appEventHandler(e) {
	Ti.API.info("@@@ '" + e.type + "' event received.");
	if ((Ti.Platform.name === "android") || (Ti.Platform.name === "windows")) {
		Ti.UI.createNotification({
			message: e.type,
			duration: Ti.UI.NOTIFICATION_DURATION_SHORT,
		}).show();
	}
}

Ti.App.addEventListener("resume", appEventHandler);
Ti.App.addEventListener("resumed", appEventHandler);
Ti.App.addEventListener("pause", appEventHandler);
Ti.App.addEventListener("paused", appEventHandler);
Ti.App.addEventListener("close", appEventHandler);

var rootWindow = Ti.UI.createWindow({ title: "Parent Window" });
var openButton = Ti.UI.createButton({ title: "Open Child" });
openButton.addEventListener("click", function() {
	var childWindow = Ti.UI.createWindow({ title: "Child Window" });
	var closeButton = Ti.UI.createButton({ title: "Close Child" });
	closeButton.addEventListener("click", function() {
		childWindow.close();
	});
	childWindow.add(closeButton);
	childWindow.open();
});
rootWindow.add(openButton);
rootWindow.open();

Comments

  1. Joshua Quick 2019-01-18

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10634
  2. Joshua Quick 2019-01-30

    PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10658
  3. Satyam Sekhri 2019-03-20

    FR Passed. Waiting on Jenkins build.
  4. Christopher Williams 2019-03-25

    merged to master, 8_0_X
  5. Samir Mohammed 2019-03-26

    *Closing ticket.* Fix verified in SDK version 8.0.1.v20190325125116 and SDK Version 8.1.0.v20190325115012. Test and other information can be found at: PR (master): https://github.com/appcelerator/titanium_mobile/pull/10634 PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10658

JSON Source