4

I am overriding the backbutton with a onBackPressed() function

how do I also detect long clicks on the backbutton? Is there an equivalent of @Override onBackLongPressed() ?

CQM
  • 42,592
  • 75
  • 224
  • 366

4 Answers4

3

This might help you (Check the first comment) - Android long key press

Community
  • 1
  • 1
Suchi
  • 9,989
  • 23
  • 68
  • 112
2

From Android 2.0, Activity contains the method

public boolean onKeyLongPress(int keyCode, KeyEvent event)

For exemple, a long key press on the back button would be :

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) 
    {
        // do your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}
1

Check "Story 2" here. There's not a shortcut for it like there is onBackPressed().

Rob
  • 2,779
  • 5
  • 23
  • 34
1

I think you'll have to use onKeyLongPress and handle the KEYCODE_BACK event yourself.

Kristian
  • 6,443
  • 6
  • 27
  • 29