|
1 | | -# Global Exception Handler |
2 | 1 |
|
| 2 | +# GlobalExceptionHandler |
3 | 3 |
|
| 4 | + |
4 | 5 |
|
| 6 | +Rather than showing the default boring system error dialog, it serves to open the |
| 7 | +desired Activity whenever the Application crashes. And it has only 2 functions |
5 | 8 |
|
6 | 9 |
|
7 | 10 |
|
8 | 11 |
|
| 12 | +## Usage/Examples |
| 13 | + |
| 14 | +App.kt |
| 15 | +```kotlin |
| 16 | +class App : Application() { |
| 17 | + override fun onCreate() { |
| 18 | + super.onCreate() |
| 19 | + GlobalExceptionHandler.initialize(this,CrashActivity::class.java) |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +App.kt |
| 25 | +```kotlin |
| 26 | +class CrashActivity : AppCompatActivity() { |
| 27 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 28 | + super.onCreate(savedInstanceState) |
| 29 | + GlobalExceptionHandler.getThrowableFromIntent(intent).let { throwable -> |
| 30 | + // Report the crash error to your servers or etc... |
| 31 | + } |
| 32 | + setContentView(view) |
| 33 | + } |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +## Functions |
| 38 | + |
| 39 | +#### Initalize the GlobalExceptionHandler |
| 40 | + |
| 41 | +```kotlin |
| 42 | + GlobalExceptionHandler.initalize(applicationContext, activityToBeLaunched) |
| 43 | +``` |
| 44 | + |
| 45 | +| Parameter | Type | Description | |
| 46 | +| :-------- | :------- | :------------------------- | |
| 47 | +| `applicationContext` | `Context` | Required to launch Intent | |
| 48 | +| `activityToBeLaunched` | `Activity` | The activity to be launched whenerver app crashes | |
| 49 | + |
| 50 | +#### Get Throwable from Intent |
| 51 | + |
| 52 | +```kotlin |
| 53 | + GlobalExceptionHandler.getThrowableFromIntent(intent): Throwable? |
| 54 | +``` |
| 55 | + |
| 56 | +| Parameter | Type | Description | |
| 57 | +| :-------- | :------- | :-------------------------------- | |
| 58 | +| `intent` | `Intent` | Retrives crash data from intent. It should be called inside of the **activityToBeLaunched** Activity. | |
| 59 | + |
| 60 | +## Screenshots |
| 61 | +With GlobalExceptionHandler | Without GlobalExceptionHandler |
| 62 | +--- | --- |
| 63 | + |  |
| 64 | + |
0 commit comments