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
[geshi lang=”mxml” nums=”1″ target=”_self” ]
1 2 3 4 |
override protected function backKeyUpHandler(event:KeyboardEvent):void { event.preventDefault(); } |
[geshi lang=”mxml” nums=”1″ target=”_self” ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version="1.0" encoding="utf-8"?> <s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" backgroundAlpha="0.5" backgroundColor="0x000000" width="90%" > <s:Panel title="Alert" horizontalCenter="0" verticalCenter="0" width="90%" > <s:VGroup horizontalAlign="center" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="10" width="100%"> <fx:Script> <![CDATA[ private function onClick(close:Boolean):void { if(close) NativeApplication.nativeApplication.exit(); // Important bit else this.close(); } ]]> </fx:Script> <s:Label text="Exit Application?" width="100%" textAlign="center" paddingTop="40" color="#000000"/> <s:HGroup width="100%" paddingTop="60"> <s:Button label="Yes" width="50%" click="onClick(true)"/> <s:Button label="No" width="50%" click="onClick(false)"/> </s:HGroup> </s:VGroup> </s:Panel> </s:SkinnablePopUpContainer> |
1 |
1 2 |
override protected function backKeyUpHandler(event:KeyboardEvent):void { |
1 2 |
var popupyn:PopUp = new PopUp(); popupyn.open(this); |
1 |
} |
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!
Cheers
Leave a Reply