5

我正在调用getExternalCacheDir()我的 Android 应用程序上的功能,这导致某些具有以下设备(HUAWEI P30 lite、Galaxy A40、Xperia XZ3)的 Android 10 用户出现 ANR。

我的 ANR 有以下堆栈跟踪

The "main" (tid=1) thread is performing disk I/O.
"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x72dfcb58 self=0x73e23a5000
  | sysTid=12158 nice=0 cgrp=default sched=0/0 handle=0x73e3913ee8
  | state=D schedstat=( 378582885 304333911 539 ) utm=23 stm=14 core=7 HZ=100
  | stack=0x7fc28de000-0x7fc28e0000 stackSize=8192KB
  | held mutexes=
  at libcore.io.Linux.access (Native method)
  at libcore.io.ForwardingOs.access (ForwardingOs.java:73)
  at libcore.io.BlockGuardOs.access (BlockGuardOs.java:71)
  at libcore.io.ForwardingOs.access (ForwardingOs.java:73)
  at android.app.ActivityThread$AndroidOs.access (ActivityThread.java:7816)
  at java.io.UnixFileSystem.checkAccess (UnixFileSystem.java:281)
  at java.io.File.exists (File.java:815)
  at android.app.ContextImpl.ensureExternalDirsExistOrFilter (ContextImpl.java:2838)
  at android.app.ContextImpl.getExternalCacheDirs (ContextImpl.java:787)
- locked <0x0614cac6> (a java.lang.Object)
  at android.app.ContextImpl.getExternalCacheDir (ContextImpl.java:779)
  at android.content.ContextWrapper.getExternalCacheDir (ContextWrapper.java:289)
  at com.mypackage.util.file.FileManager.initialize (FileManager.java:51)

当我阅读开发人员参考时,我没有看到任何通知说我们需要在主线程之外进行调用:https://developer.android.com/reference/android/content/Context#getExternalCacheDir()

我应该在不同的线程上拨打电话吗?解决该 ANR 的最简单方法是什么?

4

0 回答 0