3 Replies Latest reply on Mar 5, 2013 2:18 PM by francoland

    Flex 4.6 Mobile- soft keyboard and andorid back button


      Forgive me as I posted this question in another thread but it doesn't seem to be getting much attention.


      When using Flex 4.6 on Android I've noticed an undesired behavior related to the soft keyboard.


      When the soft keyboard is open and you press the hardware back button two things happen:

      First, the keyboard closes.

      Then, if you're on a secondary view you get a pop view or if you're on the home view the app closes.


      I've been trying to solve this by overriding the hardware back button but have yet to come up with anything that works. It seems most of the posted solutions are for older versions of Flex and don't seem to work in 4.6


      Both of my phones I'm testing this on are HTC's incase this is hardware specific.

        • 1. Re: Flex 4.6 Mobile- soft keyboard and andorid back button
          frank_aq Level 1

          Looks like I've been able to fix this (at least on my phone (HTC Evo Shift 4G)


          Here is one of my views with the fix. Basically, I'm checking to see if a text field has focus and only popping if it doesn't. It should be easy enough to write a custom text field class an use a static var that all views could check off of.


          I will admit I am a bit worried that this issue may be related to my hardware (my phone has a physical keyboard) or the sense ui. If anyone has a different phone to test this on; I've included a link to my FXP and I'm looking forward to your feedback!


          <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                  xmlns:s="library://ns.adobe.com/flex/spark" title="TestView" backKeyPressed="onBackKeyPressed( event )" >





          import mx.events.FlexEvent;

                      private var kb:Boolean = false

                      private function onBackKeyPressed( e:FlexEvent ):void {






                          } else {

                              stage.focus = null;








          <s:TextInput focusIn="kb = true" focusOut="kb = false" />


          FXP project with my fix can be found here: http://francisaltomare.com/_etc/TestBackKey.fxp

          • 2. Re: Flex 4.6 Mobile- soft keyboard and andorid back button

            Hi, frank! I have likely the same issue.It's in your project too.

            Way to reproduce:

            1) Activate keyboard at the second view in textInput.

            2) Press back. (Keyboard will disapper.)

            3) Press back. App will exit, but it' will not return to the previous view, as it should be.


            I've tested it on Galaxy Nexus and Xperia Ray and Air 3.1/3,2.

            • 3. Re: Flex 4.6 Mobile- soft keyboard and andorid back button

              Hi GEG_man and frank,

              try to do as shown in the code below works for me, I tried to simplify the code to SoftKeyboard to prevent the application exits on pressing the back button:



              <?xml version="1.0" encoding="utf-8"?>

              <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"


                      title="Test SoftKeyBoard" viewActivate="view1_viewActivateHandler(event)" backKeyPressed="backKeyPressedHandler(event)"




                          import mx.events.FlexEvent;

                          import spark.events.IndexChangeEvent;

                          import spark.events.TextOperationEvent;

                          import spark.events.ViewNavigatorEvent;


                          private var focusInOut:Boolean = false;


                          protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void


                              message.text = data.description;




                          protected function backKeyPressedHandler( event:FlexEvent ):void {

                              //trace("Trigger: "+event.type);

                              //trace("USER_TRIGGERED: "+SoftKeyboardTrigger.USER_TRIGGERED.length);

                              if(SoftKeyboardTrigger.USER_TRIGGERED.length == 13 && focusInOut==true){


                                  stage.focus = stage;

                              } else {

                                   stage.focus = null;




                          protected function recipient_softKeyboardActivateHandler(event:SoftKeyboardEvent):void


                              trace("Activate: "+event.type);


                              stage.focus = null;




                          protected function recipient_softKeyboardDeactivateHandler(event:SoftKeyboardEvent):void


                              //trace("Deactivate: "+event.type);


                              stage.focus = stage;







                  <s:TextArea id="message" width="100%" height="300" change="message_changeHandler(event)" text="{data.description}"

                              softKeyboardActivate="recipient_softKeyboardActivateHandler(event)" softKeyboardDeactivate="recipient_softKeyboardDeactivateHandler(event)"

                              focusIn="focusInOut=true" focusOut="focusInOut=false"/>




              I've tested it on Galaxy S3 and LG P990 and Air 3.4/3,5/3.6.