Android中捕獲全局異常實(shí)現(xiàn)代碼
1、實(shí)現(xiàn)UncaughtExceptionHandler,在方法uncaughtException中處理沒(méi)有捕獲的異常。
public class GlobalException implements UncaughtExceptionHandler { private final static GlobalException myCrashHandler = new GlobalException(); private GlobalException() { } public static synchronized GlobalException getInstance() { return myCrashHandler; } public void uncaughtException(Thread arg0, Throwable arg1) { Trace.Log("-------------caught Exception--"); } }
2、繼承Application ,在其中調(diào)用Thread方法setDefaultUncaughtExceptionHandler,來(lái)捕獲異常
代碼:
public class MyApplication extends Application { public void onCreate() { super.onCreate(); GlobalException handler = GlobalException.getInstance(); Thread.setDefaultUncaughtExceptionHandler(handler); } }
相關(guān)文章
圖解 Kotlin SharedFlow 緩存系統(tǒng)及示例詳解
這篇文章主要為大家介紹了圖解 Kotlin SharedFlow 緩存系統(tǒng)及示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Android自定義View實(shí)現(xiàn)可以拖拽的GridView
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)可以拖拽的GridView,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06Android編程布局(Layout)之AbsoluteLayout用法實(shí)例分析
這篇文章主要介紹了Android編程布局(Layout)之AbsoluteLayout用法,結(jié)合實(shí)例形式簡(jiǎn)單分析了Android絕對(duì)布局AbsoluteLayout的實(shí)現(xiàn)方法,需要的朋友可以參考下2015-12-12Kotlin引用其他xml的view對(duì)象過(guò)程詳解
這篇文章主要介紹了Kotlin中如何引用其他xml中的view對(duì)象,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-02-02Android啟動(dòng)頁(yè)廣告(騰訊廣告聯(lián)盟)解決方法及源碼下載
這篇文章主要介紹了Android啟動(dòng)頁(yè)廣告(騰訊廣告聯(lián)盟)解決方法的相關(guān)資料,啟動(dòng)頁(yè)幾乎成為了每個(gè)app的標(biāo)配,有些商家在啟動(dòng)頁(yè)中增加了開(kāi)屏廣告以此帶來(lái)更多的收入,需要的朋友可以參考下2017-03-03Android身份證號(hào)有效性校驗(yàn)工具類案例
這篇文章主要介紹了Android身份證號(hào)有效性校驗(yàn)工具類案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09