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

如何防止android應(yīng)用程序由于后臺(tái)線程異常而崩潰

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

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

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:

背景:

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

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.

由于庫本身創(chuàng)建了后臺(tái)線程 - 我不能只通過 try/catch 包裝它們.

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

問題

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

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?

相關(guān)問題

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

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 擴(kuò)展所有活動(dòng).該應(yīng)用永遠(yuǎn)不會(huì)崩潰

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());
            }
        });
    }
}

這篇關(guān)于如何防止android應(yīng)用程序由于后臺(tái)線程異常而崩潰?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 香蕉视频一区二区 | 成人亚洲网 | 久草在线 | 美女国内精品自产拍在线播放 | 国产精品一区二区久久久久 | 天天躁日日躁狠狠很躁 | 日韩精品在线一区二区 | 99精品国自产在线 | 日韩在线一区二区三区 | 在线欧美亚洲 | 国产成人精品在线 | 欧美日韩专区 | 国产精品免费观看 | 九色视频网站 | 四虎影院在线观看免费视频 | 人人干人人艹 | 精品av天堂毛片久久久借种 | 欧美三级在线 | 欧美极品视频在线观看 | 91精品在线看 | 成人精品鲁一区一区二区 | 亚洲v区| 国产成人久久精品一区二区三区 | 国产精品无码久久久久 | 在线永久看片免费的视频 | 国产精品久久久久久久久久免费 | 欧美一区视频在线 | 久草热播| 一级片免费网站 | 亚洲电影第1页 | 亚洲欧美成人影院 | 黄色网址大全在线观看 | 国产一级淫片a直接免费看 免费a网站 | 中文字幕日韩欧美一区二区三区 | 欧美啊v在线观看 | 国产免费人成xvideos视频 | 久久国产精品久久久久久 | 国产网站在线免费观看 | 91精品国产综合久久香蕉922 | 激情六月天| 亚洲精品一区二区 |