Flex Mobile – Preventing the Back Button Event Android

Hi Guys,

There are many occasions when you would like to prevent or override default back button event for android devices. One of them is say when your present user with a login screen and they log in successfully and then you push a target view to the view stack, what if someone press hardware back button? Some questions that may arise in this situation is if you are offering in built session support or something equivalent to “remember me” functionality what happens? I guess user log-in View is shown again because the hardware Back button behaves a little bit different to your in view “popView” handler.

To prevent the default Back button event is really simple?

  • Override backKeyUpHandler  function of your ViewNavigatorApplication
Here is how its done:
In your application main file enter the following code

[geshi lang=”mxml” nums=”1″ target=”_self” ]

Above code is enough to stop default event to occur.
Even better what If you would like to ask your user a question (when they hit hardware back key say) “do you want to Exit this application?” how you go about this?
Lets find out how?
To start with create a SkinnablePopUpContainer and save it as PopUp.mxml under your components package or may be anywhere you like.

[geshi lang=”mxml” nums=”1″ target=”_self” ]

Now edit the overridden  backKeyUpHandler function to include this code [geshi lang=”mxml” nums=”1″ target=”_self” ]

and thats it you get the following result










I hope this helps. If it does answer your question please leave your comments as a feedback, Ta!



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.