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

  • Home
  • SEARCH
  • 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 8176001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:59:08+00:00 2026-06-06T22:59:08+00:00

CustomExceptionHandler public class CustomExceptionHandler implements UncaughtExceptionHandler { private Context ctx; private ContentResolver cr; public

  • 0

CustomExceptionHandler

public class CustomExceptionHandler implements UncaughtExceptionHandler {

private Context ctx;
private ContentResolver cr;

public CustomExceptionHandler(Context ctx, ContentResolver cr) {
    this.ctx = ctx;
    this.cr = cr;
}

public void uncaughtException(Thread t, Throwable e) {

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);
    String stacktrace = result.toString();
    printWriter.close();


    String deviceUuid = Utilities.DeviceUuid(ctx, cr);
    String bluetoothName = Utilities.LocalBluetoothName();

    AsyncTasks.ErrorLogTask logTask = new AsyncTasks.ErrorLogTask(e, bluetoothName, deviceUuid, stacktrace);
    logTask.execute();
}




}

Called from my main activity:

Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(getBaseContext(), getContentResolver()));

When an exception occurs now, i dont get the regular “unfortunately, has stopped” popup. Its just a black screen. If i remove my call from my main activity, in other words dont use the CustomExceptionHandler anymore, i get the default behaviour.

Is there any way to implement the default error behaviour in my class?

Thanks in advance!

  • 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-06-06T22:59:10+00:00Added an answer on June 6, 2026 at 10:59 pm

    You can add the following at the end of your exception handler to get the “unfortunately has stopped” dialog:

    System.exit(1);
    

    However, this will cause the process to terminate which means that your AsyncTask will not run to completion.

    In any case, I would doubt that your code will run reliably anyway if you are in an uncaughtExceptionHandler, because you have no idea what the state of your application is. It might work, and it might not. What you could also try is to create a new Thread in your uncaughtExceptionHandler and have that thread sleep for a little while and then terminate the application using System.exit(). That may give your AsyncTask enough time to run to completion.

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

Sidebar

Related Questions

I got to know about this Java 1.5 capability recently and I developed a
I have recently inherited a J2EE Struts web app that was written back in
I'm developing a JSF 2.0 application on Glassfish v3 and i'm trying to handle
My site is completely custom, as such I like to know when I have
I have an ant task that contains javac task inside. It reports about error
I've seen it happen a few times already but I can't seem to find
Some clients experience an app crash directly when they launch it. Here's the code
My android app is taking more and more memory over time. I took a

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.