Connect with us


Gracefully handling Android app crashes

No Crashes do not equal No Bugs.

To have your app crash in the hands of the users is the ultimate failure for any developer. That naturally raises the question of how do we make our app 100% crash-free. Well, that’s what we will find out today. But before we begin I want to make it clear that we will be simply handling the crash and preventing our app from crashing by no means does that mean our app does not have a bug. No Crashes do not equal No Bugs.

Alright now for the fun part. We will start by creating an Interface to handle our crashes lets call it ExceptionListener.

In our application class, we will implement the ExceptionListener interface and put the code here to handle the crash and indicate to the user that something is wrong.

Now for the actual code that will catch our error. We will add the below method in the application class and call it in the onCreate of the application class. This method will simply set up a listener and call the uncaughtException method we created earlier.

Just in case you are wondering this is the complete application.

Note: In the implementation of the ExceptionListener.uncaughtException() is where you would put something like firebase in place and log the error so you can handle the errors better in the future version. This is by no means a fix to your crashes. This is simply a gracefully way to handle your errors.

Full Article: Mukesh Solanki @ ProAndroidDev