0

In my app sometimes the user clicks on the back button, and there is no response, so they click again right away, and instead of going back to previous screen they go 2-3 screens back. Sometimes out of the app entirely. And yet these back clicks all occured while just one screen was shown! Is there any way to intercept this and ignore these follow up back clicks. Perhaps observe their spacing or the screen in which they occured? Does anyone else have this problem?

My guess is nothing can be done because the user has ultimate control over back button, but why does Android not ignore the extra clicks since they all happen on the same page and it has not even stated to switch??

Code Droid
  • 10,344
  • 17
  • 72
  • 112
  • http://stackoverflow.com/questions/2459848/android-prompt-user-to-save-changes-when-back-button-is-pressed – DeeV Sep 06 '12 at 20:55
  • 4
    This sounds like you're masking a bigger issue though (i.e., why does it take forever to respond to an exit request?). – DeeV Sep 06 '12 at 20:56
  • Well there is a ListView showing typically. Its not optimized because I am not sure when this request (back request) is processed exactly. Do you know? – Code Droid Sep 06 '12 at 20:57
  • btw, whats the downvote/close about? don't mind but don't get it. – Code Droid Sep 06 '12 at 21:07
  • 1
    Your app failing to immediately respond to a Back button press (necessitating the extra presses) is a bad sign. Are you performing long tasks on the UI thread that would be better suited for a separate thread? – Cloudy Sep 06 '12 at 21:22

1 Answers1

8

You can catch the back button easily with the below code, however you should really not be taking forever to respond. Your UI thread is blocked doing something and this is fundamentally wrong.

@Override
public void onBackPressed() {
  // do something on back.
  return;
}
Glebbb
  • 356
  • 1
  • 8
  • You don't need to release resources if you're popping from the back stack. The only things that need to be done are closing sockets and ending threads. I suppose deleting temp files if you created them. None of these things should take forever to do like you say. – DeeV Sep 07 '12 at 13:24