0

I'm having a weird issue; my app won't close when i press the back button, even if i override the onBackPressed with a finish() it won't work...

@Override
public void onBackPressed() {

    finish();
}

What can cause this? maybe a handler not closed or something?

Thanks

Motheus
  • 533
  • 5
  • 21
  • 1
    have you use Fragment or Activity ? – Haresh Chhelana Oct 20 '14 at 04:23
  • It's an activity that loads a fragment in a Frameview, it also call classes with network/IO methods. – Motheus Oct 20 '14 at 04:27
  • Add super.onBackPressed(); – Hulk Oct 20 '14 at 04:27
  • 1
    possible duplicate of [How can I close my application on back pressed in android](http://stackoverflow.com/questions/8799558/how-can-i-close-my-application-on-back-pressed-in-android) – Ragaisis Oct 20 '14 at 04:31
  • 1
    @Ragaisis Read the question properly before claiming it's a duplicate. – Michael Yaworski Oct 20 '14 at 04:32
  • normally you don;t have to override onBackPressed method to finish the activity...as it's the implicit/default operation of back button in android.....whereas on your problem...try using @Override public boolean onKeyDown(int keyCode,KeyEvent event) {if(keyCode==event.KEYCODE_BACK)finish():} – Angad Tiwari Oct 20 '14 at 05:42

1 Answers1

0

it is because you have removed super ..add super in your onBackPressed method

@Override
 public void onBackPressed()
 {

  super.onBackPressed();  
  finish();
}
Meenal
  • 2,879
  • 5
  • 19
  • 43
  • and if it is a fragment then call popBackStack() method – Meenal Oct 20 '14 at 04:27
  • I had a piece of bad code plus forgot to call the super. So i'll mark this as the right answer. Thanks – Motheus Oct 20 '14 at 04:34
  • 2
    @Motheus `super.onBackPressed()` just calls `finish()`. I don't think this is the correct answer. They do the same thing. The reason it works for you now is probably because of the bad code you said you had. – Michael Yaworski Oct 20 '14 at 04:34