ExceptionHandler – Custom UI

Bored seeing default Crash Dialog? You can open custom Activity when your App Crashes where you can report crash to Firebase Crashlytics or any other URL you want.

Installation

Step 1

Add the JitPack repository to your settings.gradle file

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } // Add this
    }
}

Step 2

Add the dependency

dependencies {
    implementation 'com.github.niraj-prajapati:ExceptionHandler:1.0.0'
}

Usage

Create Activity for custom view of Crash. Let’s assume the activity is named CrashActivity.kt.

Initialize ExceptionHandler in App.kt

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        ExceptionHandler.initialize(this, CrashActivity::class.java)
    }
}

Get crash in CrashActivity.kt and send it to firebase or server wherever needed.

class CrashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ExceptionHandler.getThrowableFromIntent(intent).let {
            Log.e("TAG", "Error Data: ", it)
            // TODO: send report to your server or firebase
            // Firebase.crashlytics.log(it)
        }
        setContentView(view)
    }
}

Your contributions are welcome.

Demo App

I have prepared a Demo App for you.

Leave a Comment