• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to handle device back key into android App ?

Hi,
I am working on the one application where I used single activity but I have taken multiple classes that extends Framelayout. I am moving from one state to another within application with the help of ViewFlipper.

But problem is that when I press BACK KEY(Device) then the view is going previous state but into cycle, means how many times I moves from main menu to another sub state it is moving that multi times. I want when the main Menu state come using back key it should not repeat again.

Please tell me how to restrict it, but I don't want to block this device back key functionality.

Please help me.

Thanks in Advance,
Arthur
:confused:
 
Hi,
Thanks for quick replay. Sir, when I override this method(onBackPressed() ) into the activity . This method is calliing but I want to override this method into every class that extends FrameLayout instead of main Activity class. Because I have to do some specific work into every class separately during Back Key pressed. When I override onBackPressed() method into all classes separately, but it is not executing from classes(extends FrameLayout) but it is executed from my Activity class only.

Please give some more idea to handle it.

Thanks and Regards,
Arthur
 
Hmm, you could try something like using this. it's an interface in the view package so should be available to a FrameLayout.

KeyEvent.Callback | Android Developers

public abstract boolean onKeyUp (int keyCode, KeyEvent event)

Since: API Level 1

Called when a key up event has occurred.

Parameters

keyCode The value in event.getKeyCode(). event Description of the key event.
Returns


  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
And then you would listen for:

KeyEvent | Android Developers

public static final int KEYCODE_BACK

Since: API Level 1
Key code constant: Back key.

Constant Value: 4 (0x00000004)

does that help?
 
Hi,
Thanks alostpacket, I override this method(onKeyUp (int keyCode, KeyEvent event)) into class that extends FrameLayout, but unfortunately it is still not calling. But what method I override inside of activity class that only called during execution. It should call but I dont know why it is not callling.......

Waiting for more idea !!!


Thanks and Regards,
Andy
 
Back
Top Bottom