0

I want to cancel all notifications related to my app when the back button is clicked. I am not able to find a way. Have you any idea?

user1471575
  • 731
  • 2
  • 15
  • 23

2 Answers2

0

Hope it help

@Override

public void onBackPressed() {

// write code for canceling the notification
return;

}

Dhrupal
  • 1,863
  • 1
  • 23
  • 38
  • My problem is that I don't know how to cancel all notifications – user1471575 Sep 11 '12 at 06:23
  • Ok what kind of notification you want cancel? – Dhrupal Sep 11 '12 at 06:25
  • I am downloading a file from a server using an asynctask and I am updating my notification bar in the "onProgressUpdate". I want to stop download and cancel notification on back pressed. – user1471575 Sep 11 '12 at 06:25
  • Ok means you want to stop operation which is done in async task, right? In that case in async task write below method instead of writing in onProgressUpdate @Override protected void onPreExecute() { mProgressDialog = new ProgressDialog(this.context); mProgressDialog.setMessage("Loading wait....."); mProgressDialog.setIndeterminate(true); mProgressDialog.setCancelable(true); mProgressDialog.getWindow().setGravity(Gravity.BOTTOM); mProgressDialog.show(); } – Dhrupal Sep 11 '12 at 06:29
  • Check these links http://stackoverflow.com/questions/3740103/how-to-collapse-android-notifications https://github.com/commonsguy/cw-android/blob/master/Notifications/Notify1/src/com/commonsware/android/notify/NotifyDemo.java – Randroid Sep 11 '12 at 06:30
0

this may Helps you

   @Override
    public void onBackPressed() {    
    stopSelf();
    return;
    }
Ankitkumar Makwana
  • 3,475
  • 3
  • 19
  • 45