Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6621593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:17:11+00:00 2026-05-25T21:17:11+00:00

In my application I have several services running. When user stop application (UI part)

  • 0

In my application I have several services running. When user stop application (UI part) services remain running in the background and display notifications ( each service has one) in status bar. When clicking on it dialog appears with choice to cancel appropriate service.

And here is my problem. When something goes wrong and application crashes notifications remains in the status bar area. Is it possible to clear all notifications before showing standard android force close dialog?

The real bug is NPE when I try to open activity clicking on notification. It’s fixed. But I only want to know how to clear everything when application crashes.


Here is my final solution inspired by mice’s post. In application in on create method I register Thread.setDefaultUncaughtExceptionHandler()

@Override
public void onCreate() {
    super.onCreate();
    this.notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
    UncaughtExceptionHandler appHandler = new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            this.notificationManager.cancelAll();
            defaultHandler.uncaughtException(thread, ex);
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(appHandler);
}

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:17:12+00:00Added an answer on May 25, 2026 at 9:17 pm

    You may call

    Thread.setDefaultUncaughtExceptionHandler()

    with a handler to be called when some Exception is not handled by your app in the thread.
    This handler is invoked in case Thread dies due to an unhandled exception.

    Here you’d do needed cleanup work.

    This is exactly how ACRA crash reporting library is catching crashes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application written in C# that consumes several internal web services.
So I have a web application that integrates with several other APIs and services
In my application I have several activities, the main screen has 4 buttons that
I have several tabs in my application, and each tab loads a different sub-page
I have several WCF services in an ASP.NET application. I want to prevent applications
We have an application running as a Windows service on a production server. The
We have a 3 tier application - winform based thick client, several WCF services
My application is implemented as a service (running under services.exe). I am adding a
I have a Windows Service (written in .NET 1.1) running under a specific user
We have a number of services (mostly console applications) running across several remote computers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.