- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Android 应用程序遇到了一些 ANR 问题,因此我实现了 StrictMode 策略。以前从未使用过这个,所以希望有人可以帮助解释以下内容:
为什么日志显示 2 个看似相似的违规行为,除了前 4 行和持续时间不同?为什么还是有 2 次违规——这是否意味着代码被执行了两次?
感谢任何帮助
08-15 14:24:14.314: DEBUG/StrictMode(767): StrictMode policy violation; ~duration=13876 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=17 violation=1
at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:732)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1791)
at com.j256.ormlite.android.AndroidCompiledStatement.execSql(AndroidCompiledStatement.java:151)
at com.j256.ormlite.android.AndroidCompiledStatement.runUpdate(AndroidCompiledStatement.java:70)
at com.j256.ormlite.stmt.StatementExecutor.update(StatementExecutor.java:382)
at com.j256.ormlite.dao.BaseDaoImpl.update(BaseDaoImpl.java:374)
at conx.Repositories.JobRepository.update(JobRepository.java:381)
at conx.Presenters.JobSchedulePresenter.onSave(JobSchedulePresenter.java:200)
at conx.Activities.JobScheduleActivity.onSaveEvent(JobScheduleActivity.java:111)
at conx.Activities.JobScheduleActivity.access$100(JobScheduleActivity.java:43)
at conx.Activities.JobScheduleActivity$2.onChildClick(JobScheduleActivity.java:169)
at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:588)
at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:527)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1877)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
08-15 14:24:14.314: DEBUG/StrictMode(767): StrictMode policy violation; ~duration=12086 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=17 violation=1
at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:732)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:52)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1809)
at com.j256.ormlite.android.AndroidCompiledStatement.execSql(AndroidCompiledStatement.java:151)
at com.j256.ormlite.android.AndroidCompiledStatement.runUpdate(AndroidCompiledStatement.java:70)
at com.j256.ormlite.stmt.StatementExecutor.update(StatementExecutor.java:382)
at com.j256.ormlite.dao.BaseDaoImpl.update(BaseDaoImpl.java:374)
at conx.Repositories.JobRepository.update(JobRepository.java:381)
at conx.Presenters.JobSchedulePresenter.onSave(JobSchedulePresenter.java:200)
at conx.Activities.JobScheduleActivity.onSaveEvent(JobScheduleActivity.java:111)
at conx.Activities.JobScheduleActivity.access$100(JobScheduleActivity.java:43)
at conx.Activities.JobScheduleActivity$2.onChildClick(JobScheduleActivity.java:169)
at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:588)
at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:527)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1877)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
StrictMode 违规表明您正在导致 ANR 问题的 UI 线程上执行 SQLite 查询。
尝试在单独的线程上执行数据库交互,这将防止出现 ANR 问题并防止显示这些 StrictMode 违规行为。
通过浏览 LogCat
输出,它看起来像是发生在 conx.Activities.JobScheduleActivity.onSaveEvent
一些有用的读物:
关于Android StrictMode 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963601/
我在 React 实践中发现了这个组件,但我不知道确切的行为是什么。 例如 const App = () => { return ( Welcome to
我有一个 JSON 函数在不同的 Activity 中以相同的格式正常工作,但是当我在这里运行它时,我收到错误。我已经确定了实际的 JSON 调用,该调用抛出了异常,但不知道为什么。请参阅 'JSON
我的问题是这样的,我正在尝试了解此跟踪的来源: 11-06 22:07:36.593 2744-3492/com.spot.spottester W/f: Suppressed StrictMode
这个问题在这里已经有了答案: Strict mode in android 2.2 (6 个答案) 关闭 7 年前。 StrictMode.ThreadPolicy policy = new Str
我正在尝试使用函数作为组件内的 prop,并且该组件是另一个组件的子组件。但该功能不起作用。?我可以知道为什么吗?这是我在控制台中收到的警告。 Warning: findDOMNode is depr
当我在 Android 2.3.6 上运行这段代码时,它工作正常。在 4.0 上我得到一个 StrictMode 异常。从关于 SO 的一些问题来看,您似乎无法在 UI 线程上进行网络操作。但我没有在
Draggable 包在严格模式下导致错误: Warning: findDOMNode is deprecated in StrictMode. findDOMNode waspassed an in
在应用发布之前,我在 Google Play 中出现以下错误。这不是警告,而是错误。我可以看到带有类似堆栈跟踪的警告。我不确定该应用程序是否会因此而被拒绝,因为发布前报告的摘要令人困惑。它说没有问题。
我正在开发我的第一个 Android 应用程序,并且主要基于研究内置。当我尝试登录我的用户时,我得到了 android.os.NetworkOnMainThreadException错误。我在网上读到
当我打开严格模式检测全部时,我的应用程序崩溃了应用程序的 super.onCreate()(即,甚至在我的任何代码执行任何操作之前)。 我的应用程序 onCreate 开启严格模式如下 overrid
Android 应用程序遇到了一些 ANR 问题,因此我实现了 StrictMode 策略。以前从未使用过这个,所以希望有人可以帮助解释以下内容: 为什么日志显示 2 个看似相似的违规行为,除了前 4
当 Android 的 StrictMode 检测到泄漏对象(例如 Activity )违规时,如果我能及时捕获堆转储,那将会很有帮助。但是,没有明显的方法来配置它来执行此操作。有谁知道可以用来实现它
我一直在尝试在 StrictMode 中运行我的应用程序,以检查是否存在任何可能已经潜入的隐藏问题。我遇到的一个问题是在使用 ContentResolver 时似乎是 Leaked DatabaseC
我已经开始使用 Android StrictMode 并发现在开发过程中让它始终运行会很棒,而不仅仅是在我在 git 中创建的特殊分支上。我这样做的原因是我的应用程序要求运行 1.6 及更高版本。 我
实际上,我正在尝试编写一个具有 minSDKversion:8 和 targetSDKversion:15 的应用,我需要使用 StrictMode.ThreadPolicy policy =
我正在运行我的应用程序,并在开发中激活了 StrictMode,如此处所述 StrictMode for lower platform versions并注意到一条错误消息,我不知道该怎么想,也找不到
经过一番试验,我发现在严格模式下会出现以下问题。 如果有人可以解释原因,我会很感兴趣。 举这个简单的例子,里面渲染 我只是安排一个更新状态的超时 : Example : let firstRender
当启用 StrictMode 时,它总是提示 FileReader 有 DiskReadViolation。无论我如何改进,它仍然存在。我怀疑它与 UIThread 滞后问题有关,请告诉我如何解决
我是 android 的新手,正在调试现有的应用程序。当应用程序运行时,我遇到了 StrictMode 策略违规。我想了解违规发生后采取了哪些措施?我正在粘贴日志。 D/StrictMode( 454
我只想使用 StrictMode.noteSlowCall 。我不知道该怎么办。开发者网站/androidxref 没有足够的解释。 下面是我的代码。 @Override public void on
我是一名优秀的程序员,十分优秀!