1、Activity中报异常之后导致应用崩溃吗?
A: 肯定会发生崩溃啊,自己上手一实验,惊奇的发现ActivityA启动ActivityB后,ActivityB抛异常后,ActivityA居然还活着?这是什么情况?
经过一番百度发现,这是Activity的崩溃恢复
首先要知道ActivityB报错之后,该App的进程绝壁会被Kill掉的,这是默认的异常处理器,看finally
private static class UncaughtHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e) {
try {
// Don't re-enter -- avoid infinite loops if crash-reporting crashes.
if (mCrashing) return;
mCrashing = true;
if (mApplicationObject == null) {
Clog_e(TAG, "*** FATAL EXCEPTION IN SYSTEM PROCESS: " + t.getName(), e);
} else {
StringBuilder message = new StringBuilder();
message.append("FATAL EXCEPTION: ").append(t.getName()).append("\n");
final String processName = ActivityThread.currentProcessName();
if (processName != null) {
message.append("Process: ").append(processName).append(", ");
}
message.append("PID: ").append(Process.myPid());
Clog_e(TAG, message.toString(), e);
}
// Try to end profiling. If a profiler is running at this point, and we kill the
// process (below), the in-memory buffer will be lost. So try to stop, which will
// flush the buffer. (This makes method trace profiling useful to debug crashes.)
if (ActivityThread.currentActivityThread() != null) {
ActivityThread.currentActivityThread().stopProfiling();
}
// Bring up crash dialog, wait for it to be dismissed
ActivityManagerNative.getDefault().handleApplicationCrash(
mApplicationObject, new ApplicationErrorReport.CrashInfo(e));
} catch (Throwable t2) {
if (t2 instanceof DeadObjectException) {
// System process is dead; ignore
} else {
try {
Clog_e(TAG, "Error reporting crash", t2);
} catch (Throwable t3) {
// Even Clog_e() fails! Oh well.
}
}
} finally {
// Try everything to make sure this process goes away.
Process.killProcess(Process.myPid());
System.exit(10);
}
}
}
系统会重新新建一个进程,仅将栈顶的Activity进行恢复,调用onCreate(),onRestoreSavaInstance()等等一系列操作。
PS:如果Activity运行在其他进程当中,发生崩溃,并不会导致主进程的崩溃。还是见finally中代码。。。。
2、为什么要用Glide,Glide的优势
我TM只会用啊。。。。
Glide支持三级缓存,支持加载Gif,bitmap为RGB_565,占用内存较小
三级缓存:
- 内存缓存
使用LRUCache算法,底层实现使用LinkedHashMap,LinkedHashMap在HashMap的基础上扩展了一个双向链表来记录顺序,顺序可选择是插入顺序还是访问顺序。 - 硬盘缓存
- 网络获取
网友评论