Android 8.1.0 调试笔记 - 处理 “Duplicate finish request for ActivityRecord”_Water_Marking的博客-程序员宅基地

        在测试工具 app 中进行某一项测试时,界面突然挂了。分析日志,发现日志中 crash 的地方是输入法?喵喵喵!?

        总的来说,报错日志像下面这样:

//log...

01-25 18:19:23.050 W/ActivityManagerService(  442): Duplicate finish request for ActivityRecord{62dbc14 u0 com.xxxxx.xxxxx.xxxxxfactorytest/com.xxxxx.xxxxx.quicktest.view.cameratest.CameraPreviewActivity t6 f}

01-25 18:19:23.086 W/InputMethodManagerService(  442): Focus gain on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@2f26bf84 (uid=10030 pid=17034)

//log...

01-25 18:19:23.387 W/ActivityManagerService(  442): Duplicate finish request for ActivityRecord{894bc62 u0 com.xxxxx.xxxxx.xxxxxfactorytest/com.xxxxx.xxxxx.quicktest.view.cameratest.CameraPreviewActivity t6 f}

01-25 18:19:23.431 W/InputMethodManagerService(  442): Focus gain on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@2f26bf84 (uid=10030 pid=17034)

//log...

01-25 19:09:39.187 E/libc++abi(17034): (null)

--------- beginning of crash

01-25 19:09:39.187 F/libc    (17034): Fatal signal 6 (SIGABRT), code -6 in tid 21041 (aierfactorytest)

01-25 19:09:39.187 I/libc    (17034): Suppressing debuggerd output because prctl(PR_GET_DUMPABLE)==0

//log...

//log...

01-25 19:09:39.568 D/AndroidRuntime(21065): Shutting down VM

01-25 19:09:39.572 D/CrashHandler(21065): crash file:/mnt/sdcard/factorytest/crash2013_01_25_19_09:39.log

01-25 19:09:39.572 W/System.err(21065): java.io.IOException: open failed: EINVAL (Invalid argument)

01-25 19:09:39.572 W/System.err(21065): 	at java.io.File.createNewFile(File.java:941)

01-25 19:09:39.572 W/System.err(21065): 	at com.xxxxx.xxxxx.xxxxxfactorytest.CrashHandler.writeToSDcard(CrashHandler.java:86)

01-25 19:09:39.572 W/System.err(21065): 	at com.xxxxx.xxxxx.xxxxxfactorytest.CrashHandler.uncaughtException(CrashHandler.java:53)

01-25 19:09:39.572 W/System.err(21065): 	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)

01-25 19:09:39.572 W/System.err(21065): 	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

01-25 19:09:39.572 W/System.err(21065): Caused by: android.system.ErrnoException: open failed: EINVAL (Invalid argument)

01-25 19:09:39.573 W/System.err(21065): 	at libcore.io.Posix.open(Native Method)

01-25 19:09:39.573 W/System.err(21065): 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)

01-25 19:09:39.573 W/System.err(21065): 	at java.io.File.createNewFile(File.java:934)

01-25 19:09:39.573 W/System.err(21065): 	... 4 more

01-25 19:09:39.573 W/System.err(21065): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.xxxxx.xxxxxfactorytest/com.xxxxx.xxxxx.xxxxxfactorytest.view.burningtest.BurningTestActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0

01-25 19:09:39.573 W/System.err(21065): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)

01-25 19:09:39.573 W/System.err(21065): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)

01-25 19:09:39.573 W/System.err(21065): 	at android.app.ActivityThread.access$800(ActivityThread.java:151)

01-25 19:09:39.573 W/System.err(21065): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1319)

01-25 19:09:39.573 W/System.err(21065): 	at android.os.Handler.dispatchMessage(Handler.java:102)

01-25 19:09:39.573 W/System.err(21065): 	at android.os.Looper.loop(Looper.java:135)

01-25 19:09:39.573 W/System.err(21065): 	at android.app.ActivityThread.main(ActivityThread.java:5280)

01-25 19:09:39.573 W/System.err(21065): 	at java.lang.reflect.Method.invoke(Native Method)

01-25 19:09:39.573 W/System.err(21065): 	at java.lang.reflect.Method.invoke(Method.java:372)

01-25 19:09:39.573 W/System.err(21065): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)

01-25 19:09:39.573 W/System.err(21065): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)

01-25 19:09:39.573 W/System.err(21065): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0

01-25 19:09:39.573 W/System.err(21065): 	at android.content.res.Resources.getValue(Resources.java:1283)

01-25 19:09:39.573 W/System.err(21065): 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2667)

01-25 19:09:39.573 W/System.err(21065): 	at android.content.res.Resources.getLayout(Resources.java:1099)

01-25 19:09:39.574 W/System.err(21065): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:412)

01-25 19:09:39.574 W/System.err(21065): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:365)

01-25 19:09:39.574 W/System.err(21065): 	at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)

01-25 19:09:39.574 W/System.err(21065): 	at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)

01-25 19:09:39.574 W/System.err(21065): 	at com.xxxxx.xxxxx.xxxxxfactorytest.view.base.BaseActivity.onCreate(BaseActivity.java:57)

01-25 19:09:39.574 W/System.err(21065): 	at android.app.Activity.performCreate(Activity.java:6222)

01-25 19:09:39.574 W/System.err(21065): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)

01-25 19:09:39.574 W/System.err(21065): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)

01-25 19:09:39.574 W/System.err(21065): 	... 10 more

01-25 19:09:39.574 E/AndroidRuntime(21065): FATAL EXCEPTION: main

01-25 19:09:39.574 E/AndroidRuntime(21065): Process: com.xxxxx.xxxxx.xxxxxfactorytest, PID: 21065

01-25 19:09:39.574 E/AndroidRuntime(21065): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.xxxxx.xxxxxfactorytest/com.xxxxx.xxxxx.xxxxxfactorytest.view.burningtest.BurningTestActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread.access$800(ActivityThread.java:151)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1319)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.os.Handler.dispatchMessage(Handler.java:102)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.os.Looper.loop(Looper.java:135)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread.main(ActivityThread.java:5280)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at java.lang.reflect.Method.invoke(Native Method)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at java.lang.reflect.Method.invoke(Method.java:372)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)

01-25 19:09:39.574 E/AndroidRuntime(21065): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.content.res.Resources.getValue(Resources.java:1283)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2667)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.content.res.Resources.getLayout(Resources.java:1099)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:412)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:365)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at com.xxxxx.xxxxx.xxxxxfactorytest.view.base.BaseActivity.onCreate(BaseActivity.java:57)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.Activity.performCreate(Activity.java:6222)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)

01-25 19:09:39.574 E/AndroidRuntime(21065): 	... 10 more

01-25 19:09:39.577 W/ActivityManagerService(  442):   Force finishing activity 1 com.xxxxx.xxxxx.xxxxxfactorytest/.view.burningtest.BurningTestActivity

        为什么会打印 Duplicate finish request for ActivityRecord{ ...CameraPreviewActivity t6 f}呢?

        为什么会打印 Focus gain on non-focused client  IInputMethodClient (uid=10030 pid=17034) 呢?

        查找源码发现:

        "Duplicate finish..."  之所以会被打印出来,是因为回调到了系统服务 ActivityStack.java 的 finishActivityLocked()方法:

    /**
     * @return Returns true if this activity has been removed from the history
     * list, or false if it is still in the list and will be removed later.
     */
    final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData,
            String reason, boolean oomAdj) {
        if (r.finishing) {
            Slog.w(TAG, "Duplicate finish request for " + r);
            return false;
        }


     //code......

        return false;
    }

 

        "Focus gain on non-focused client" 之所以会被打印出来,是因为回调到了系统服务 InputMethodManagerService.java 的 windowGainedFocus()  方法:

    @Override
    public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
            int controlFlags, int softInputMode, int windowFlags,
            EditorInfo attribute, IInputContext inputContext) {

        // code...

        try {
            synchronized (mMethodMap) {

                //code...

                try {
                    if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
                        // Check with the window manager to make sure this client actually
                        // has a window with focus.  If not, reject.  This is thread safe
                        // because if the focus changes some time before or after, the
                        // next client receiving focus that has any interest in input will
                        // be calling through here after that change happens.
                        Slog.w(TAG, "Focus gain on non-focused client " + cs.client
                                + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
                        return null;
                    }
                } catch (RemoteException e) {


                }

          //code...
                }

            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }

        return res;
    }

        所以分析,这里应该就是代码中多次主动调用了 CameraPreviewActivity 界面的 finish() 方法,关键是在调用 finish() 方法之前,并未对当前界面的状态做判断,最后导致当前窗口获取到焦点,系统回调到了系统输入法服务 InputMethodManagerService 的 windowGainedFocus() 方法。 代码中多次错误调用界面的 finish() 方法,最终导致在 so 库中报错,应用挂掉。

        解决方法就是在finish()前通过isFinishing()判断是否已经finish 。

        吐槽一个地方,在定位源码中日志输出 " Duplicate finish request ... " 的时候,差点没憋死我,因为日志的 TAG 命名显示是 "ActivityManagerService" ,那按照一般人的理解,这个日志应该是在 ActivityManagerService.java 中打印出来的,可是在ActivityManagerService.java 中查找了半天,这个java 文件没有打印这句话,最后终于在热心网友的博客中发现,这行日志是在 ActivityStack.java 中打印出来的,这个类导包:import static com.android.server.am.ActivityManagerService.TAG;WTF!?

 

【参考链接】

https://www.jianshu.com/p/8cd648845705

https://blog.csdn.net/weixin_33910759/article/details/91392658

https://blog.csdn.net/kris_fei/article/details/76582585

 

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Water_Marking/article/details/98881766

智能推荐

sprd-audio-程序员宅基地

audio : machine,platform,codec.machine : vbc-rxpx-codec-sc27xx.c //platform : sprd-2stage-dmaengine-pcm.ccodec : sprd-codec.c vbc-rxpx-codec-sc27xx.c late_initcall_sync platform_driver_regis...

WPF-DataGrid设置各行变色-程序员宅基地

我在stackoverflow.com中找到的资料:The ItemContainerStyle is applied to the elements generated by the ItemsControl: ContentPresenter. The ContentPresenter will in turn contain whatever you put in your Item

java 手动调用System.gc();-程序员宅基地

*** java中手动调用 System.gc();也不能立刻让程序立刻就回收内存。这个调用相当于“建议”执行垃圾回收,但是什么时候调用是不能确定的!

计算机语言只学一门学什么,入门生信一定要学的一门编程语言,你觉得是啥-程序员宅基地

作为一名合格的生信工作者,至少都要符合以下几个条件熟练使用Linux熟练使用高通量分析工具,如BWA, SAMtools等至少熟练使用一门编程语言,C/C++, Python, Perl, Go熟练使用一门统计工具且有着良好的统计素养,如R生物学基础扎实有自己对生物学问题的见解这是我在生信技能树写了好多篇招聘工作发现一些共同点。学习Linux其实是理解一种哲学思想,分解任务各个击破,所以我写了为什...

mysql5.7.17主从复制_mysql5.7安装与主从复制_首席情感咨询顾问的博客-程序员宅基地

一、 下载mysql5.7http://mirrors.sohu.com/mysql/MySQL-5.7/Linux下载:输入命令:wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz二、 建立用户,以及mysql的目录1、 建立一个mysql..._mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz主从同步复制

【linux】解决CentOS 7系统root用户下Chrome无法启动问题_centos7 chrome 您使用的是不受支持的命令行标记: --no-sandbox-程序员宅基地

在CentOS 7系统root用户下安装Chrome后发现无法正常启动。安装及问题解决具体如下:1. 官网下载https://www.google.cn/chrome/google-chrome-stable_current_x86_64.rpm2. 双击此文件进行安装,或者rpm -ivh google-chrome-stable_current_x86_64.rpm执行过程可能会报缺少依赖包,安装对应依赖包就可以3. 安装完毕之后,将在应用程序--->网络--->中发_centos7 chrome 您使用的是不受支持的命令行标记: --no-sandbox

随便推点

Mongodb中的聚合函数使用:按月统计数量_mongodb 统计一年内每个月的数量-程序员宅基地

案例:mongodb中有统计表(stat_list)表,存有每天的统计数据,现在需要按月计算,则需要用到mongo的聚合函数aggregate。 "_id" : ObjectId("5d00d3b66939c1efb80ba325"), "date" : "2019-06-12", "daily_count" : "164.34万",解决方案:1、将daily_count去掉万字,然后..._mongodb 统计一年内每个月的数量

软核操作系统-程序员宅基地

转载于:https://www.cnblogs.com/xujing6/p/6390193.html_软核移植操作系统

表单脚本-程序员宅基地

  打算实现模拟表单控件的DEMO,首先把《JavaScript高级程序设计》“表单脚本”这章的内容复习一下,有针对性地看书,希望可以提高效率。1 表单基础知识  表单对应的是HTMLFormElement类型,HTMLFormElement继承了HTMLElement,具有其他HTML元素的默认属性,同时享有一些独特的属性和方法。acceptCharset服务器能够处..._脚本工具获取表单信息并处理表单信息

Linux图形界面GNOME和KDE终获统一_kde gnome 2018-程序员宅基地

INQ报道,开源开发实验室(OSDL)和freedesktop.org发布了GNOME和KDE统一界面的预览版。该项目命名为Portland,采用两套界面:一套命令行工具和一个被称为DAPI的API库。Portland Project能简化GNOME和KDE桌面环境中程序的移植和集成过程。Linux开发人员可以利用DAPI来自定义服务,并在不同桌面版之间维持同样的界面集合,简化基础的桌面整合任务。_kde gnome 2018

基于python的学生成绩管理系统毕业设计源码071143_python学生成绩管理系统设计报告_FYKJ_2010的博客-程序员宅基地

管理员:首页、个人中心、轮播图、公告栏、用户管理、新闻列表、新闻分类、删除申请管理、学生成绩管理、核对申请管理秘书:首页、学生管理、删除管理、学生成绩、个人信息任课老师:首页、个人中心、学生成绩、核对申请学生:首页、个人中心、我的成绩、核对申请_python学生成绩管理系统设计报告

课堂笔记-程序员宅基地

1. 多态形式1: 父类pet做形参 子类dog做实参 父类作为返回值形式2. 多态类型的转换 父类做类型,子类实例化2.重写的方法 1)位置:子类和父类有同名的方法 2)方法名相同,返回类型和修饰符相同,方法体不同多态的优势 1.可以减少类中的代码量,可以提高代码的可扩展性和可维护性 2 向上转型——子类...