NeverCrash全局捕获Crash的库
NeverCrash for Android 一个全局捕获Crash的库。信NeverCrash,永不Crash。
Gif 展示
引入
Maven:
<dependency> <groupId>com.king.thread</groupId> <artifactId>nevercrash</artifactId> <version>1.0.0</version> <type>pom</type> </dependency>
Gradle:
compile 'com.king.thread:nevercrash:1.0.0'
Lvy:
<dependency org='com.king.thread' name='nevercrash' rev='1.0.0'> <artifact name='$AID' ext='pom'></artifact> </dependency>
如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie)
allprojects { repositories { maven { url 'https://dl.bintray.com/jenly/maven' } } }
示例
核心代码(大道至简)
NeverCrash.init(CrashHandler);
代码示例
public class App extends Application { @Override public void onCreate() { super.onCreate(); NeverCrash.init(new NeverCrash.CrashHandler() { @Override public void uncaughtException(Thread t, Throwable e) { Log.d("Jenly", Log.getStackTraceString(e)); // e.printStackTrace(); showToast(e.getMessage()); } }); } private void showToast(final String text){ new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show(); } }); } }
评论