java android错误:无法从parcel读取输入通道文件描述符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31433987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 18:36:57  来源:igfitidea点击:

android error: Could not read input channel file descriptors from parcel

javaandroid

提问by janse

I've made an application for Android that works more or less like this:

我已经为 Android 制作了一个应用程序,其工作方式或多或少是这样的:

  • Application communicates with the Web service and transfers information (not files)
  • I can navigate to a different screen using Intentand startActivity
  • 应用程序与 Web 服务通信并传输信息(不是文件)
  • 我可以使用Intent和导航到不同的屏幕startActivity

Unfortunately, sometimes the application crashes with the following error in different activity:

不幸的是,有时应用程序会在不同的活动中因以下错误而崩溃:

java.lang.RuntimeException: Could not read input channel file descriptors from parcel.  
at android.view.InputChannel.nativeReadFromParcel(Native Method)  
at android.view.InputChannel.readFromParcel(InputChannel.java:135)  
at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:523)  
at android.view.ViewRootImpl.setView(ViewRootImpl.java:481)  
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)  
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)  
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)  
at android.view.Window$LocalWindowManager.addView(Window.java:537)  
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2507)  
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)  
at android.app.ActivityThread.access0(ActivityThread.java:123)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)  
at android.os.Handler.dispatchMessage(Handler.java:99)  
at android.os.Looper.loop(Looper.java:137)  
at android.app.ActivityThread.main(ActivityThread.java:4424)  
at java.lang.reflect.Method.invokeNative(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:511)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)  
at dalvik.system.NativeStart.main(Native Method) 

But I don't know what does this error mean because I don't work with files. Any idea?

但我不知道这个错误是什么意思,因为我不处理文件。任何的想法?

回答by user1643723

This question appears to be the same as Could not read input channel file descriptors from parcel, which was (incorrectly) closed as off-topic. It is also more or less same as Could not read input channel file descriptors from parcel crash report. Unfortunately those questions haven't gotten a satisfactory (and sufficiently general) answer, so I am going to try anyway.

这个问题似乎与无法从parcel 读取输入通道文件描述符相同,后者被(错误地)关闭为题外话。它也或多或少与无法从包裹崩溃报告中读取输入通道文件描述符相同。不幸的是,这些问题没有得到令人满意的(且足够笼统的)答案,所以无论如何我都会尝试。

File descriptors are used in multiple places in Android:

文件描述符在 Android 中的多处使用:

  • Sockets (yes, open network connections are "files" too);
  • Actual files (not necessarily files on disks, may as well be android.os.MemoryFileinstances);
  • Pipes—Linux uses them everywhere, for example the attempt to open pipe, that resulted in your exception, was likely required to send input events between IME (keyboard) process and your application.
  • 套接字(是的,开放的网络连接也是“文件”);
  • 实际文件(不一定是磁盘上的文件,也可能是android.os.MemoryFile实例);
  • 管道——Linux 在任何地方都使用它们,例如尝试打开管道,导致您的异常,可能需要在 IME(键盘)进程和您的应用程序之间发送输入事件。

All descriptors are subject to shared maximum limit; when that count is exceeded, your app begins to experience seriousproblems. Having the process die is the best scenario in such case, because otherwise the kernel would have run out of memory (file descriptors are stored in kernel memory).

所有描述符均受共享最大限制;当超过该计数时,您的应用程序开始遇到严重问题。在这种情况下,进程死亡是最好的情况,因为否则内核将耗尽内存(文件描述符存储在内核内存中)。

You may have issues with descriptors (files, network connections) not being closed. You must close them ASAP. You may also have issues with memory leaks—objects not being garbage-collected when they should (and some of leaked objects may in turn hold onto file descriptors).

您可能会遇到未关闭描述符(文件、网络连接)的问题。您必须尽快关闭它们。您可能还会遇到内存泄漏问题——对象在应该时没有被垃圾收集(并且一些泄漏的对象可能反过来保留文件描述符)。

Your own code does not have to be guilty, libraries you use and even some system components may have bugs, leading to memory leaks and file descriptor leaks. I recommend you to use Square's Leak Canary—a simple, easy to use library for automatic detection of leaks (well, at least memory leaks, which are most frequent).

您自己的代码不必有罪,您使用的库甚至某些系统组件都可能存在错误,从而导致内存泄漏和文件描述符泄漏。我建议您使用Square 的 Leak Canary— 一个简单易用的库,用于自动检测泄漏(好吧,至少是内存泄漏,这是最常见的)。

回答by Bob Snyder

The crash may be caused by too much activity on the device resulting in the system running out of file descriptors. Although you may not declare files or file descriptors in your code, they are used internally by the system and the number used increases with the number of activities, services, threads, etc. Your stack trace is very similar to many of the stack traces in AOSP issue 32470. A first step toward solving the crash may be to review your design to confirm that you are not creating an excessive number of threads/activities/services/etc.

崩溃可能是由设备上的过多活动导致系统耗尽文件描述符引起的。虽然您可能不会在代码中声明文件或文件描述符,但它们由系统内部使用,并且使用的数量随着活动、服务、线程等的数量而增加。您的堆栈跟踪与许多堆栈跟踪非常相似AOSP 问题 32470。解决崩溃的第一步可能是检查您的设计以确认您没有创建过多的线程/活动/服务/等。

You might also try running with StrictMode.VmPolicyenabled to see if resources are being leaked.

您还可以尝试在启用StrictMode.VmPolicy 的情况下运行以查看资源是否泄漏。

回答by Lin XiaoDong

In my case, the cause of the problem is creating too much threads. I had created more than one thousand requests in a for loop incorrectly, finally trigger this problem. People who face with this problem need to avoid this situation.

就我而言,问题的原因是创建了太多线程。我在 for 循环中错误地创建了超过一千个请求,最终触发了这个问题。遇到这个问题的人需要避免这种情况。