1

Hey I have the following code within my application, however when I use the back button to close my music activity or the main menu it does not seem to work as the music still plays even when the back button has been pressed to exit the app. However it does work for my film activity/film clips could anyone explain what may be the problem?

I do not get any errors:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
        this.finish();
    }
    return super.onKeyDown(keyCode, event);
}
salezica
  • 74,081
  • 25
  • 105
  • 166
Thomas
  • 293
  • 1
  • 3
  • 15

2 Answers2

0

You can use this in your activity

 @Override
public void onBackPressed() {
    this.finish();
}
AwadKab
  • 3,054
  • 2
  • 17
  • 17
0

The best solution for Android API 5+ would be:

@Override
public void onBackPressed() {
    super.onBackPressed();
}

However, it's the default behavior. So your problem should be somewhere else.

Show some code for more detail.

Hartok
  • 2,147
  • 20
  • 37