1. Download our Official Android App: Forums for Android!

Apps How can you tell if the "Back" button on the device is pressed.

Discussion in 'Android Development' started by MIIISTER NEUGIT, Nov 12, 2010.

  1. MIIISTER NEUGIT

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Nov 12, 2010

    Nov 12, 2010
    17
    0
    15
    Xbox 360 Game Developer
    In my application I need to be able to invoke a method when the back button on the device is pressed. How do I do that?
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    You need to override the onBackPressed() method
     
    MIIISTER NEUGIT likes this.
  3. MIIISTER NEUGIT

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Nov 12, 2010

    Nov 12, 2010
    17
    0
    15
    Xbox 360 Game Developer
    Well When I put this:

    @Override
    public void onBackPressed()
    {

    }

    It gives an error and tells me to remove the @Override annotion.

    Is there any package that needs importing first?

    BTW I am developing for android 1.1
     
  4. MIIISTER NEUGIT

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Nov 12, 2010

    Nov 12, 2010
    17
    0
    15
    Xbox 360 Game Developer
    Nevermind, I discovered that since I am developing for the first android I have to override onKeyDown.
     
  5. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    Okey. Good to know ;)
     

Share This Page

Loading...