cat.ereza.customactivityoncrash.config.CaocConfig Java Examples
The following examples show how to use
cat.ereza.customactivityoncrash.config.CaocConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.java From CoolViewPager with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); CaocConfig.Builder.create() .backgroundMode(CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM .enabled(true) //default: true .showErrorDetails(true) //default: true .showRestartButton(true) //default: true .logErrorOnRestart(true) //default: true .trackActivities(true) //default: false .minTimeBetweenCrashesMs(2000) //default: 3000 .errorDrawable(null) //default: bug image .restartActivity(null) //default: null (your app's launch activity) .errorActivity(CustomErrorActivity.class) //default: null (default error activity) .eventListener(null) //default: null .apply(); }
Example #2
Source File: ActivityCustomError.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_error); //TextView errorDetailsText = (TextView) findViewById(R.id.error_details); //errorDetailsText.setText(CustomActivityOnCrash.getStackTraceFromIntent(getIntent())); Button restartButton = (Button) findViewById(R.id.restart_button); restartButton.setBackgroundColor(Color.parseColor(G.appBarColor)); final Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); final CaocConfig config = CustomActivityOnCrash.getConfigFromIntent(getIntent()); restartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CustomActivityOnCrash.restartApplicationWithIntent(ActivityCustomError.this, i, config); } }); }
Example #3
Source File: G.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); G.firstTimeEnterToApp = true; new Thread(new Runnable() { @Override public void run() { Fabric.with(getApplicationContext(), new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build()); CaocConfig.Builder.create().backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT).showErrorDetails(false).showRestartButton(true).trackActivities(true).restartActivity(ActivityMain.class).errorActivity(ActivityCustomError.class).apply(); } }).start(); context = getApplicationContext(); handler = new Handler(); inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); Raad.init(getApplicationContext()); Utils.setInstart(context, "fa"); WebBase.apiKey = "5aa7e856ae7fbc00016ac5a01c65909797d94a16a279f46a4abb5faa"; new StartupActions(); }
Example #4
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 6 votes |
/** * Given an Intent, restarts the app and launches a startActivity to that intent. * The flags NEW_TASK and CLEAR_TASK are set if the Intent does not have them, to ensure * the app stack is fully cleared. * If an event listener is provided, the restart app event is invoked. * Must only be used from your error activity. * * @param activity The current error activity. Must not be null. * @param intent The Intent. Must not be null. * @param config The config object as obtained by calling getConfigFromIntent. */ public static void restartApplicationWithIntent(@NonNull Activity activity, @NonNull Intent intent, @NonNull CaocConfig config) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (intent.getComponent() != null) { //If the class name has been set, we force it to simulate a Launcher launch. //If we don't do this, if you restart from the error activity, then press home, //and then launch the activity from the launcher, the main activity appears twice on the backstack. //This will most likely not have any detrimental effect because if you set the Intent component, //if will always be launched regardless of the actions specified here. intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); } if (config.getEventListener() != null) { config.getEventListener().onRestartAppFromErrorActivity(); } activity.finish(); activity.startActivity(intent); killCurrentProcess(); }
Example #5
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 5 votes |
/** * Given an Intent, returns the config extra from it. * * @param intent The Intent. Must not be null. * @return The config, or null if not provided. */ @Nullable public static CaocConfig getConfigFromIntent(@NonNull Intent intent) { CaocConfig config = (CaocConfig) intent.getSerializableExtra(CustomActivityOnCrash.EXTRA_CONFIG); if (config != null && config.isLogErrorOnRestart()) { String stackTrace = getStackTraceFromIntent(intent); if (stackTrace != null) { Log.e(TAG, "The previous app process crashed. This is the stack trace of the crash:\n" + getStackTraceFromIntent(intent)); } } return config; }
Example #6
Source File: IApplication.java From DanDanPlayForAndroid with MIT License | 4 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override public void onCreate() { super.onCreate(); _context = this.getApplicationContext(); _asset = _context.getAssets(); //AndroidUtilsCode Utils.init(this); //skins SkinCompatManager.withoutActivity(this) // 基础控件换肤初始化 .addInflater(new SkinMaterialViewInflater()) // material design 控件换肤初始化[可选] .addInflater(new SkinConstraintViewInflater()) // ConstraintLayout 控件换肤初始化[可选] .addInflater(new SkinCardViewInflater()) // CardView v7 控件换肤初始化[可选] .addInflater(new SkinFlycoTabLayoutInflater()) .setSkinStatusBarColorEnable(true) // 关闭状态栏换肤,默认打开[可选] .setSkinWindowBackgroundEnable(true) // 关闭windowBackground换肤,默认打开[可选] .setSkinAllActivityEnable(true) .loadSkin(); //Crash CaocConfig.Builder.create() .backgroundMode(CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM) .enabled(true) .trackActivities(true) .minTimeBetweenCrashesMs(2000) .restartActivity(SplashActivity.class) .errorActivity(CrashActivity.class) .apply(); //Bugly Bugly.init(getApplicationContext(), SoUtils.getInstance().getBuglyAppId(), false); //Sophix SophixManager.getInstance().setPatchLoadStatusStub(CommonUtils.getPatchLoadListener()); //thunder XLTaskHelper.init(this); //数据库 DataBaseManager.init(this); //播放器配置 PlayerConfigShare.initPlayerConfigShare(this); //检查补丁 if (AppConfig.getInstance().isAutoQueryPatch()){ SophixManager.getInstance().queryAndLoadNewPatch(); } startCorrectlyFlag = true; //严格模式 //strictMode(); }
Example #7
Source File: SampleCrashingApplication.java From CustomActivityOnCrash with Apache License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); //You can uncomment any of the lines below, and test the results. CaocConfig.Builder.create() //Customizes what to do when the app crashes while it is in background. Possible values: //BackgroundMode.BACKGROUND_MODE_SHOW_CUSTOM: launch the error activity when the app is in background, //BackgroundMode.BACKGROUND_MODE_CRASH: launch the default system error when the app is in background, //BackgroundMode.BACKGROUND_MODE_SILENT: crash silently when the app is in background, // .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //This disables the interception of crashes. Use it to disable CustomActivityOnCrash (for example, depending on your buildType). // .enabled(false) //This hides the "error details" button in the error activity, thus hiding the stack trace // .showErrorDetails(false) //This avoids the app from using the "Restart app" button and displaying a "Close app" button directly. //Even with restart app enabled, the Close app can still be displayed if your app has no launch activity. // .showRestartButton(false) //This makes the library track the activites visited by the user and their lifecycle calls. //Use it if you want that info in the error details screen shown on the error activity. // .trackActivities(true) //This hides the additional log shown when the error activity is launched. //It is shown by default because the Android Studio Logcat view by default only shows //the current process output, and this makes the stack trace more obvious to find. // .logErrorOnRestart(false) //Defines the time that must pass between app crashes to determine that we are not in a crash loop. //If a crash has occurred less that this time ago, the error activity will not be launched //and the system crash screen will be invoked. // .minTimeBetweenCrashesMs(2000) //This shows a different image on the error activity, instead of the default upside-down bug. //You may use a drawable or a mipmap. // .errorDrawable(R.mipmap.ic_launcher) //This sets the restart activity. //If you set this, this will be used. However, you can also set it with an intent-filter: // <action android:name="cat.ereza.customactivityoncrash.RESTART" /> //If none are set, the default launch activity will be used. // .restartActivity(MainActivity.class) //This sets a custom error activity class instead of the default one. //If you set this, this will be used. However, you can also set it with an intent-filter: // <action android:name="cat.ereza.customactivityoncrash.ERROR" /> //If none are set, the default launch activity will be used. //Comment it (and disable the intent filter) to see the customization effects on the default error activity. //Uncomment to use the custom error activity // .errorActivity(CustomErrorActivity.class) //This sets a EventListener to be notified of events regarding the error activity, //so you can, for example, report them to Google Analytics. // .eventListener(new CustomEventListener()) .apply(); //Initialize your other error handler as normal. //i.e., ACRA.init(this); //or Fabric.with(this, new Crashlytics()); //If you use ACRA, remember to enable alsoReportToAndroidFramework! }
Example #8
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 4 votes |
public static void restartApplication(@NonNull Activity activity, @NonNull CaocConfig config) { Intent intent = new Intent(activity, config.getRestartActivityClass()); restartApplicationWithIntent(activity, intent, config); }
Example #9
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 3 votes |
/** * Closes the app. * If an event listener is provided, the close app event is invoked. * Must only be used from your error activity. * * @param activity The current error activity. Must not be null. * @param config The config object as obtained by calling getConfigFromIntent. */ public static void closeApplication(@NonNull Activity activity, @NonNull CaocConfig config) { if (config.getEventListener() != null) { config.getEventListener().onCloseAppFromErrorActivity(); } activity.finish(); killCurrentProcess(); }
Example #10
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 2 votes |
/** * INTERNAL method that returns the current configuration of the library. * If you want to check the config, use CaocConfig.Builder.get(); * * @return the current configuration */ @RestrictTo(RestrictTo.Scope.LIBRARY) @NonNull public static CaocConfig getConfig() { return config; }
Example #11
Source File: CustomActivityOnCrash.java From CustomActivityOnCrash with Apache License 2.0 | 2 votes |
/** * INTERNAL method that sets the configuration of the library. * You must not use this, use CaocConfig.Builder.apply() * * @param config the configuration to use */ @RestrictTo(RestrictTo.Scope.LIBRARY) public static void setConfig(@NonNull CaocConfig config) { CustomActivityOnCrash.config = config; }