Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25977] Android: AlertDialog not firing "click" event when canceled

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-04-19T22:36:14.000+0000
Affected Version/sRelease 7.1.0
Fix Version/sRelease 7.3.0
ComponentsAndroid
Labelsalertdialog, andoid, eventlistener, parity
Reporterjosh.mocek
AssigneeJoshua Quick
Created2018-04-19T14:31:26.000+0000
Updated2018-06-19T17:58:42.000+0000

Description

The alert dialog doesn't fire a cancel event if you press outside of the alertDialog box in 7.1.0. The event listener actually doesn't console anything if done this way. If you switch it back to 6.2.2 it works correctly and fires the eventlistener when the user touches outside of the alert dialog. Make a sample AppSellHerHater project and paste the index.js below. Then build to android on 7.1.0 and watch it not work. Then build with 6.2.2 and watch it work correctly.
//Replace the index.js code with this
function doClick(e) {
	myAlert.show();
}

$.index.open();

var myAlert = Ti.UI.createAlertDialog({
	cancel: 1,
	buttonNames: ['Ok', 'Cancel'],
	message: "Event listener doesn't fire if you press outside of alert on android...",
	title: 'Confirm Ok'
});

myAlert.addEventListener('click', function(e) {
	console.info('e.index: ' + e.index);
	$.label.text = (e.index == 0) ? "You pressed 'Ok'..." : "You cancelled the alert...";
	alert('e.index: ' + e.index);
});

Comments

  1. Joshua Quick 2018-04-19

    I believe the change for [TIMOB-25919] will resolve this issue as well. That ticket's change is scheduled to be made in Titanium 7.2.0. Stay tuned.
  2. Joshua Quick 2018-04-19

    Classic app test code...
       var window = Ti.UI.createWindow();
       var button = Ti.UI.createButton({ title: "Show Alert" });
       button.addEventListener("click", function(e) {
       	var dialog = Ti.UI.createAlertDialog({
       		title: "Alert Dialog",
       		message: "This is the alert message.",
       		buttonNames: ["OK", "Cancel", "Maybe"],
       		cancel: 1,
       	});
       	dialog.addEventListener("click", function(e) {
       		Ti.API.info("@@@ Dialog 'click' index: " + e.index + ", button: " + e.button + ", cancel: " + e.cancel);
       	});
       	dialog.show();
       });
       window.add(button);
       window.open();
       
  3. Joshua Quick 2018-04-19

    Confirmed fixed by [TIMOB-25919]
  4. josh.mocek 2018-04-26

    Just making sure this is also resolved for when the back button is pressed?
  5. Joshua Quick 2018-04-26

    Yes. We've confirmed that pressing the back button will fire a "click" event matching the cancel button index as well with the above fix.
  6. Lokesh Choudhary 2018-06-19

    Verified the fix with SDK 7.3.0.v20180618182516. Closing.

JSON Source