Awesome Open Source
Awesome Open Source

DefenseCrash Document

Defense the java crash for Android applications.

License Download

DefenseCrash

The library is designed to catch Java crashes, which can be effectively reduced by integrating DefenseCrash, such as avoid NPE or IOB crashes during use, improve user experience.

Maven Configuration

  • Please add the code into your project gradle file
allprojects {
    repositories {
    	maven { url 'https://dl.bintray.com/xuuhaoo/maven/'}
    }
}
  • Make sure you already done with above instructions in project gradle files, than you need put this into Module build.gradle file
dependencies {
    compile 'com.tonystark.android:defense_crash:2.0.0'
}

DefenseCrash Integrated

We provide you two options for choosing:

  • Options 1: You should manually install the defense as following code
public class MyApp extends Application implements IExceptionHandler {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
	// step1: Initialize the lib.
        DefenseCrash.initialize();
	// setp2: Install the fire wall defense.
        DefenseCrash.install(this);
    }

    @Override
    public void onCaughtException(Thread thread, Throwable throwable, boolean isSafeMode) {
	// step3: Print the error when crashed during runtime.
        throwable.printStackTrace();
	// step4: Upload this throwable to your crash collection sdk.
    }

    @Override
    public void onEnterSafeMode() {
	// We enter the safe mode to keep the main looper loop after crashed.You’d better do nothing here,we just notify you.
    }

    @Override
    public void onMayBeBlackScreen(Throwable throwable) {
	// onLayout(),onMeasure() or onDraw() has breaks down,
	// it causes the drawing to be abnormal and the choreographer to break down.
	// We will notify you on this method,you’d better finish this activity or restart the application.
    }
}
  • Options 2: To facilitate some users, we provide a DefenseCrashApplication super class for you to integrate,as following code
public class MyApp extends DefenseCrashApplication {
    @Override
    public void onCaughtException(Thread thread, Throwable throwable, boolean isSafeMode) {
	// step1: Print the error when crashed during runtime.
        throwable.printStackTrace();
	// step2: Upload this throwable to your crash collection sdk.
    }

    @Override
    public void onEnterSafeMode() {
	// We enter the safe mode to keep the main looper loop after crashed.You’d better do nothing here,we just notify you.
    }

    @Override
    public void onMayBeBlackScreen(Throwable throwable) {
	// onLayout(),onMeasure() or onDraw() has breaks down,
	// it causes the drawing to be abnormal and the choreographer to break down.
	// We will notify you on this method,you’d better finish this activity or restart the application.
    }
}

It is Done!


Licenses

   Copyright [2018] [徐昊]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
java (28,894
android (5,554
crash (32

Find Open Source By Browsing 7,000 Topics Across 59 Categories