Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-8648

Android: android:back listener reacts when using "back" to dismiss keyboard

    Details

      Description

      Problem

      On a window with a TextField, tapping the TextField to bring up the keyboard, then tapping the android:back button closes the window. Doing the same thing on the emulator simply dismisses the keyboard.

      Actual Behavior

      Clicking the android:back button when the keyboard is displayed closes the window (because the 'android:back' event is fired).

      Expected Behavior

      Clicking the android:back button when the keyboard is displayed should just dismiss the keyboard, and not fire the 'android:back' event.

      Original Testcase

      app.js

      var win1=Ti.UI.createWindow({
                        layout:'vertical',
                        url:'win1.js',
                        backgroundColor:'gray',
                        exitOnClose:true,
                        navBarHidden:true
                      });
      win1.open();
      

      NOTE: The "android:back" event is buggy on some devices. It may never fire at all.
      You may need to try various devices to reproduce the failure case.
      To verify the expected behavior change the event to "androidback" (no colon).

      win1.js

      var win1=Ti.UI.currentWindow;
       
      var TheLabel=Ti.UI.createLabel({
              color:'black',
              text:'Click the edit, then hit the back button.  Keyboard should be dismissed, but the window should not close.',
              width:'auto'
           });
      win1.add(TheLabel);
       
      var TheTextField=Ti.UI.createTextField(
                         {color:'black',
                          width:150
                         });
      win1.add(TheTextField);
       
      function AndroidBackClicked()
      {
        win1.close();
      }
      win1.addEventListener('android:back',AndroidBackClicked);
      

      Test case to verify 'androidback' does not fire when dismissing keyboard.

      var win = Ti.UI.createWindow();
      win.add(Ti.UI.createTextField({width: '75%'}));
       
      win.addEventListener('androidback', function() {
        alert('back event fired!');
      });
       
      win.open();
      
      

      1. Run application on a device that uses a soft keyboard.
      2. Focus the textfield to bring up the soft keyboard.
      3. Hit the "back" button on the device. You should see NO alert.
      4. Hit the "back" button again. You SHOULD see an alert.

      Fail: You see two alerts (one for each "back" press).
      Pass: You only get an alert in step 4.

      Test: Closing a series of LWs using the "androidback" event.

      function openWindows() {
        ['blue', 'red', 'white'].forEach(function(color) {
          var win = Ti.UI.createWindow({backgroundColor: color});
          win.addEventListener('androidback', function() {
            alert('closing window');
            win.close();
          });
          win.open();
        });
      }
       
      var mainWindow = Ti.UI.createWindow();
       
      var button = Ti.UI.createButton({title: 'Open windows'});
      button.addEventListener('click', openWindows);
      mainWindow.add(button);
       
      mainWindow.open();
      

      1. Run application and click "Open windows".
      2. Hit the back button. You should see an alert and the window should close.
      3. Repeat step 2 for each window until all of them are closed and you are back to the main window.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                joshroesslein Josh Roesslein
                Reporter:
                bitshftr Shawn Lipscomb
              • Watchers:
                0 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-12962
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration