11

作者: Fighting_Sir | 来源:发表于2019-02-15 14:38 被阅读0次
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的基础上扩展了一个双向链表来记录顺序,顺序可选择是插入顺序还是访问顺序。
  • 硬盘缓存
  • 网络获取

相关文章

  • Every day in November

    11月1日 11月2日 11月3日 11月4日 11月5日 11月6日 11月7日 11月8日 11月9日 11月...

  • 无标题文章

    #1 #11 ##11 ###11

  • 无标题文章11

    无标题文章11无标题文章11无标题文章11无标题文章11无标题文章11无标题文章11无标题文章11无标题文章11无...

  • 2018-11-10

    2018年11/11(记录11/10实际情况) 打卡日期:2018年/11月/11 打卡累计天数:11/60 ...

  • 11月睡眠记录

    11月1日: 晚上11:40睡。 11月2号:晚上11:50睡。 11月3号: 晚上11:35睡。 11月4号:...

  • Answer

    2018/11/5 2018/11/6 2018/11/15 2018/11/17 2018/11/21 2018...

  • Chinese

    2018/11/5 2018/11/6 2018/11/15 2018/11/17 2018/11/21 2018...

  • English

    2018/11/5 2018/11/6 2018/11/15 2018/11/17 2018/11/20 2018...

  • MySQL时间函数

    1. now now() 返回当前时间戳 selectnow(); --2017-11-11 11:11:11 2...

  • 给字符串在特定位置添加特殊标识

    eg:11111111 要变成11-11-11-11; var oldStr="11111111"; //str:...

网友评论

      本文标题:11

      本文链接:https://www.haomeiwen.com/subject/auwpeqtx.html