久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何防止android應用程序由于后臺線程異常而崩潰

How to prevent android app from crashing due to exception in background thread?(如何防止android應用程序由于后臺線程異常而崩潰?)
本文介紹了如何防止android應用程序由于后臺線程異常而崩潰?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

這是一個籠統的問題,從具體場景中提出來,但我想得到一個籠統的答案,如何處理以下情況:

It's a general question, which raised from specific scenario, but I'd like to get a general answer how to deal with the following situation:

背景:

我有一個應用程序,它使用一些 3rd 方庫(廣告網絡提供商 SDK - 特別是 - AdMob SDK,基于 Google Play 服務).這個庫的功能對應用程序來說并不重要.該庫創建一個或多個后臺工作線程.有時(非常罕見的情況)這些后臺線程之一中存在未處理的異常,導致應用程序崩潰.我想忽略由這個庫引起的所有異常,不管它們的原因是什么:在最壞的情況下,應用程序用戶不會看到廣告——這比應用程序崩潰要好得多.

I have an app, which is using some 3rd party library (ad network provider SDK - specifically - AdMob SDK, based on Google Play Services). Functionality of this library is not critical for the application. The library creates one or more background worker threads. Sometimes (very rare case) there is an unhandled exception in one of these background threads, causing to crashing the application. I'd like to ignore all exceptions, caused by this library, regardless of their cause: in worst case the app user will not see an ad - it's much better than app crash.

由于庫本身創建了后臺線程 - 我不能只通過 try/catch 包裝它們.

Since the library itself creates the background threads - I cannot just wrap them by try/catch.

問題

有什么方法可以捕獲所有未處理的后臺(非主)線程異常并在這種情況下殺死線程并防止應用崩潰?

Is there any way to catch all non-handled background (non-main) thread exceptions and just to kill the thread in such case, and to prevent app crash?

相關問題

我看到了很多問題,但其中一些問題太具體(并沒有涵蓋我的情況),另一些問題是指開發人員可以控制線程創建并且能夠用 try/包裝整個線程的情況抓住.如果我仍然錯過了涉及此案例的相關問題,我將不勝感激該鏈接

I saw a lot of several questions, but some of them are too specific (and not covering my case), others refer to situation when the developer has a control on thread creation and is able to wrap the whole thread with try/catch. If I still missed the relevant question, covering this case, I will appreciate the link

推薦答案

您需要做的就是使用 BaseActivity 擴展所有活動.該應用永遠不會崩潰

All you need to do is Extend all the activities with BaseActivity. The app never crashes at any point

BaseActivity 的代碼片段:

Code sniplet for BaseActivity :

public class BaseActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
                Log.e("Error"+Thread.currentThread().getStackTrace()[2],paramThrowable.getLocalizedMessage());
            }
        });
    }
}

這篇關于如何防止android應用程序由于后臺線程異常而崩潰?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 国产www成人 | 精品一区二区三区av | 精品一区二区免费视频 | 国产精品一区二区视频 | 欧美日韩精品一区 | 亚洲电影一区 | 国产玖玖 | 91久久夜色 | 日本a∨精品中文字幕在线 亚洲91视频 | 成年人免费在线视频 | 日韩精品 | 91久久婷婷 | 国产乱码精品一区二区三区忘忧草 | 亚洲 欧美 综合 | 国产精品精品久久久 | 欧美精品久久久 | 成人av一区二区三区 | 天天综合网天天综合 | 国产精品视频一区二区三区四区国 | 久久久久一区二区三区 | 日韩成人一区 | 视频一区二区在线 | 97久久精品午夜一区二区 | 中文字幕一区二区三区乱码在线 | 欧美日韩在线观看视频 | 91在线| av毛片在线播放 | 91精品久久久 | 在线成人www免费观看视频 | 国产亚洲精品久久久久久牛牛 | 国产激情视频 | 亚洲精品电影在线观看 | 6080亚洲精品一区二区 | 欧美一区二区 | 国产资源在线视频 | 日韩一区二区在线视频 | 91久久国产精品 | 欧美一区二区三区四区在线 | 久久国产视频网 | 中文字幕在线观看第一页 | 国产精品久久久久久久久久了 |