Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16524] Android: Alert dialog appears behind window

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2014-03-10T15:37:51.000+0000
Affected Version/sRelease 3.2.1
Fix Version/sRelease 3.3.0
ComponentsAndroid
Labelsipass1
ReporterAllen Yeung
AssigneeSunila
Created2014-03-01T00:51:08.000+0000
Updated2017-03-28T23:54:31.000+0000

Description

This is an issue that originated from the camera issue: TIMOB-12848 To reproduce: 1. Run the code below 2. Take a picture
var win = Titanium.UI.createWindow();
var imageView = Ti.UI.createImageView({height: Ti.UI.FILL, width: Ti.UI.Fill});
win.add(imageView);
    Titanium.Media.showCamera({
  
        success:function(event)
        {
            Ti.API.info('#### Camera Success');
            var cropRect = event.cropRect;
            var image = event.media;
            Ti.API.info(image.length);
            var filename = Titanium.Filesystem.tempDirectory + "/"+ 'camera_photo' + new Date().getTime() + ".png";
            Ti.API.info(filename);
            var f = Titanium.Filesystem.getFile(filename);
            Ti.API.info(f.nativePath);
            if (f.exists()) {
                Ti.API.info('The file exist , trying to delete it before using it :' + f.deleteFile());
                f = Titanium.Filesystem.getFile(filename);
            }
            f.write(image);
            alert('Camera Success! The file size is '+f.size+' bytes.\n Now trying to assign it to an image on the screen (this may fail for hi res images)')
            imageView.image = f.nativePath;
        },
        cancel:function()
         
        {
            Ti.API.info('#### Camera Cancel');
        },
        error:function(error)
        {
            // create alert
            Ti.API.info('#### Camera Error');
            var a = Titanium.UI.createAlertDialog({title:'Camera'});
  
            // set message
            if (error.code == Titanium.Media.NO_CAMERA)
            {
                a.setMessage('Device does not have video recording capabilities');
            }
            else
            {
                a.setMessage('Unexpected error: ' + error.code);
            }
  
            // show alert
            a.show();
        },
        allowEditing:true
    });
win.open();
Expected result: The alert dialog should show up. Actual result: The alert dialog shows up behind the window (if you hit back to close the window, the alert dialog shows up)

Comments

  1. Sunila 2014-03-10

    I don't think this is a bug. Since the window is not yet opened when showCamera is called, the activity that is used to launch the camera activity is the root activity and the callback doesn't comeback until it is active (by pressing back). To use the window activity, try calling the showCamera in 'open' event handler of the window. Modified sample var win = Titanium.UI.createWindow(); var imageView = Ti.UI.createImageView({height: Ti.UI.FILL, width: Ti.UI.Fill}); win.add(imageView); win.addEventListener("open", function(e){ Titanium.Media.showCamera({ success:function(event) { Ti.API.info('#### Camera Success'); var cropRect = event.cropRect; var image = event.media; Ti.API.info(image.length); var filename = Titanium.Filesystem.tempDirectory + "/"+ 'camera_photo' + new Date().getTime() + ".png"; Ti.API.info(filename); var f = Titanium.Filesystem.getFile(filename); Ti.API.info(f.nativePath); if (f.exists()) { Ti.API.info('The file exist , trying to delete it before using it :' + f.deleteFile()); f = Titanium.Filesystem.getFile(filename); } f.write(image); alert('Camera Success! The file size is '+f.size+' bytes.\n Now trying to assign it to an image on the screen (this may fail for hi res images)') imageView.image = f.nativePath; }, cancel:function() { Ti.API.info('#### Camera Cancel'); }, error:function(error) { // create alert Ti.API.info('#### Camera Error'); var a = Titanium.UI.createAlertDialog({title:'Camera'}); // set message if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Device does not have video recording capabilities'); } else { a.setMessage('Unexpected error: ' + error.code); } // show alert a.show(); }, allowEditing:true }); }); win.open();
  2. Lee Morris 2017-03-28

    Closing ticket as invalid.

JSON Source