在Application onCreate时就注册ExceptionHandler,此后只要程序在抛异常后就能捕获到。
public class App extends Application{ |
CrashHandler crashHandler = CrashHandler.getInstance(); |
crashHandler.init(getApplicationContext()); |
public class LogActivity extends Activity { |
public void onCreate(Bundle savedInstanceState) { |
super.onCreate(savedInstanceState); |
setContentView(R.layout.main); |
File file = new File(Environment.getExternalStorageState() ,"crash.bin"); |
FileInputStream fis = new FileInputStream(file); |
byte[] buffer = new byte[1024]; |
throw new RuntimeException(e); |
注意,如果catch后不throw就默认是自己处理了,ExceptionHandler不会捕获异常了。
再分享一个Log的封装类,只要在这里设置DEBUG的值就能让控制台是否打印出log
public static final String TAG = "ICON"; |
public static final boolean DEBUG = true; |
public static void toast(Context context,String content){ |
Toast.makeText(context, content, Toast.LENGTH_SHORT).show(); |
public static void debug(String tag,String msg){ |
public static void debug(String msg){ |
public static void error(String tag,String error){ |
public static void error(String error){ |
