Custom Error Screen Instead of Default Crash Dialog — Android

Get rid of default crash dialog.

Mustufa Ansari
CodeChai
Published in
3 min readNov 7, 2020

--

I don’t know about you but I feel very embarrassed when I deliver an app to tester or client for testing and it get crash. That moment is very painful for me.

“Live as if you were to die tomorrow. Learn as if you were to live forever.”

I personally don’t like that crash alert dialog that appears when my app gets crash. So I found an interesting library that will show an error screen instead of an error dialog.

Let’s get started.

What I’m going to use:

  1. Kotlin
  2. Android Studio
  3. Library

After creating a new project add this dependency in your build.gradle(:app) .

implementation 'cat.ereza:customactivityoncrash:2.3.0'

I am making my custom crash layout. Like this:

Custom crash layout

I downloaded this error image from here.

Let’s do some coding part to catch the crash event and show custom screen instead of android default dialog.

Now you need to make an application class that will register in the android manifest to register crash library globally in-app.

Add this class in AndroidManifest.xml using name attribute.

AndroidManifest.xml

Now moving towards MainActivity.kt to see this in action. We need to crash our app to see the crash screen. I am implementing a crashing code in my onCreate method.

var array = mutableListOf<String>()
array[0] = "Hello"
findViewById<TextView>(R.id.textView).text = array[1]

This will crash my app as this code will generate IndexOutOfBoundException .

Let’s run the app.

Download Source code from Here:

Further Readings:

--

--

Mustufa Ansari
CodeChai

📱Android/iOS Developer 🖋️ I Write For Mobile Developers 🎓 Tech Enthusiast