11

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的基础上扩展了一个双向链表来记录顺序,顺序可选择是插入顺序还是访问顺序。
  • 硬盘缓存
  • 网络获取
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • LaunchMode & Intent Flag&TaskAffinity LaunchMode launchMo...
    我这小样儿阅读 2,688评论 0 1
  • Android之Activity系列总结(一)--Activity概览 Activity 1 创建 Activit...
    我这小样儿阅读 1,580评论 0 1
  • Android之Activity系列总结(二)--任务和返回栈 任务和返回栈 应用通常包含多个Activity。每...
    我这小样儿阅读 1,657评论 0 0
  • 你所在的高度,决定你能看见什么。 假设你站在200层楼高的楼顶,你能看见蓝天下云卷云舒。 如果你在20楼,你能极目...
    发光的树tree阅读 3,157评论 0 0
  • 人生有两个至诚至真的阶段,一个是咿呀学语、天真烂漫的少年阶段,一个是历经风雨、大智若愚的暮年阶段,前一个阶...
    奔雷游侠阅读 1,517评论 0 5

友情链接更多精彩内容