title: Android long back key press, avoid FLAG_CANCELED
body: <p>I'm trying to implement a long key press recognition, I've overridden the onKeyDown</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
  //          event.startTracking();
          if (backPressedStarted == -1) {
              progressBar.setProgress(0);
              progressBar.setVisibility(View.VISIBLE);
              backPressedStarted = System.currentTimeMillis();        
          } else {
              int pressDuration = (int) (System.currentTimeMillis() - backPressedStarted);
              progressBar.setProgress(pressDuration);
              if (pressDuration &gt; 5000)
                  showExitDialog();
          }
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>After ~3.8 sec the system dispatches an onKeyUp event with the flag: FLAG_CANCELED</p>
  
  <p>I've tried ignoring it and return true or false in the key up method but it did not seem to work...</p>
  
  <p>Is there a way around this? could I define the longest press duration?</p>
  
  <p>== UPDATE ==</p>
  
  <p>Ok, so when I remove the comment for the event tracking, the long click call back is called, and then returning true or false still does not change the end result of keyUp cancels after that period of time.</p>
  
  <p>Thanks.</p>