0

Min SDK is 7

I have a little notification on the top of the screen, but when you press the back key on the main activity, it doesn't go away. What do I need to add to my back button override to fix this?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
  • When you say notification, you mean notification in the pull-down Android notification bar? – Sam Dozor Feb 14 '12 at 15:22
  • 2
    has earlier been answered here: http://stackoverflow.com/questions/3595232/android-remove-notification-from-notification-bar – pgsandstrom Feb 14 '12 at 15:23

2 Answers2

1

From android Docs ... .To clear the status bar notification when the user selects it from the notifications window, add the "FLAG_AUTO_CANCEL" flag to your Notification. You can also clear it manually with cancel(int), passing it the notification ID, or clear all your notifications with cancelAll().

Relsell
  • 771
  • 6
  • 18
0
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
         cancelAll();
        finish();

    }
    return super.onKeyDown(keyCode, event);
}

Plz update by using this code it fixes this or not