how can i show a default screen about "some error occurred" when my app going crash anywhere . like sometimes its happened in facebook and other apps , whenever app going out of control of try catch block then automatically a screen open showing Error. please help me , if here in android have any callback if app crash.
3 Answers
You could use library called CustomActivityOnCrash
. With it, you can specify your default Activity
when the app crashes. So, to set it up do as follows:
1) Add compile 'cat.ereza:customactivityoncrash:2.2.0'
to your app
level build.gradle
.
At this point if you run your app and encounter a crash then a default error Activity
from the library will be shown.
However, if you'd like to show your own error Activity
you need to do 2 additional steps.
2) Define your error Activity
in the manifest:
<activity
android:name="CustomErrorActivity"
android:label="@string/error_title"
android:process=":error_activity" />
3) Extend your Application
class as follows:
@Override
public void onCreate() {
super.onCreate();
CaocConfig.Builder.create()
.trackActivities(true) //default: false
.errorActivity(CustomErrorActivity.class)//
.apply();
}
For more information about the library please go here

- 14,139
- 4
- 35
- 65
To show a custom activity on app crash you can use the library CustomActivityOnCrash
To use this library just follow this steps:
1.Add the dependencies to your build.gradle file
implementation 'cat.ereza:customactivityoncrash:2.2.0'
2. Add a custom activity to show the crash.
<activity
android:name="CustomErrorActivity"
android:label="@string/error_title"
android:process=":error_activity" />
3. Add these lines of code to your error acitivity that extends Application
CaocConfig.Builder.create()
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
.enabled(false) //default: true
.showErrorDetails(false) //default: true
.showRestartButton(false) //default: true
.logErrorOnRestart(false) //default: true
.trackActivities(true) //default: false
.minTimeBetweenCrashesMs(2000) //default: 3000
.errorDrawable(R.drawable.ic_custom_drawable) //default: bug image
.restartActivity(YourCustomActivity.class) //default: null (your app's launch activity)
.errorActivity(YourCustomErrorActivity.class) //default: null (default error activity)
.eventListener(new YourCustomEventListener()) //default: null
.apply();
For more information and advance customization of the library click here

- 677
- 1
- 8
- 22
You can use CustomActivityOnCrash library
@Override
public void onCreate() {
super.onCreate();
CaocConfig.Builder.create()
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
.enabled(false) //default: true
.showErrorDetails(false) //default: true
.showRestartButton(false) //default: true
.logErrorOnRestart(false) //default: true
.trackActivities(true) //default: false
.minTimeBetweenCrashesMs(2000) //default: 3000
.errorDrawable(R.drawable.ic_custom_drawable) //default: bug image
.restartActivity(YourCustomActivity.class) //default: null (your app's launch activity)
.errorActivity(YourCustomErrorActivity.class) //default: null (default error activity)
.eventListener(new YourCustomEventListener()) //default: null
.apply();
}

- 456
- 3
- 9