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.
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:
- Kotlin
- Android Studio
- 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:
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.
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.
Top comments (0)