问题

Running into some ANR issues with an android application so I implemented the StrictMode policies. Never used this before so hopefully someone can help explain the following:

Why does the log show 2 violations which are seemingly similar apart from a difference in the top 4 line and the duration? And why are there 2 violations anyway - does this mean that the code was executed twice?

Any help appreciated

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)

回答1:

The StrictMode violation is showing that you are executing an SQLite query on the UI thread which is causing the ANR issues.

Try performing database interactions on a separate thread, this will prevent the ANR issues and prevent these StrictMode violations showing.

From skimming through that LogCat output it looks like it's occuring in conx.Activities.JobScheduleActivity.onSaveEvent

Some useful reading:

http://developer.android.com/guide/components/processes-and-threads.html

http://www.vogella.com/articles/AndroidPerformance/article.html

来源:https://stackoverflow.com/questions/11963601/android-strictmode-policy

android strictmode有什么作用,Android StrictMode policy相关推荐

  1. android strictmode有什么作用,Android StrictMode运行流程(推荐)

    什么是 StrictMode(严苛模式) strictmode是android在 API9后引入的检测影响app运行流畅性的一种机制,例如我们都知道的主线程中不允许有网络操作这条规则就是严苛模式规则的 ...

  2. android strictmode有什么作用,Android 性能优化 之 StrictMode

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? StrictMode概述 StrictMode 是用来检测程序中违例情况的开发者工具.使用StrictMode,系统检测 ...

  3. android strictmode有什么作用,Android StrictMode介绍

    今天在阅读Wordpress for android 的源代码的时候看到这个. 之前项目中未曾用过,google了一下发现很有用.写篇blog记录下./** * enables "stric ...

  4. android strictmode有什么作用,Android严苛模式StrictMode使用详解

    StrictMode类是Android 2.3 (API 9)引入的一个工具类,可以用来帮助开发者发现代码中的一些不规范的问题,以达到提升应用响应能力的目的.举个例子来说,如果开发者在UI线程中进行了 ...

  5. android任务栈的作用,Android 启动模式以及任务栈

    1.Android 主要包含4种启动模式,下面分别介绍四种启动方式的特点: 1)tandard 默认的启动模式,标准模式 每开启一个Activity,就会在栈顶添加一个Activity实例.多次间隔或 ...

  6. android 单例的作用,Android中单例模式的几个坑

    先来看这样一个单例,稍微有点经验的同学可能都会说,这样的单例是非线程安全的.要加个volatile关键字才可以.class Singleton{        private static  Sing ...

  7. android小部件的作用,Android 应用小部件的实现

    有些时候,我们需要为自己的应用添加一个桌面小部件来显示一些简单但是关键的信息方便用户使用.应用小部件的视图是靠RemoteViews来展现的,而RemoteViews内只能放置一些简单的ViewGro ...

  8. android中uri的作用,Android UrlUri详细解析

    概述 在项目开发中,有时会遇到解析Url.Uri的需求,要从中得到链接中的相应字段.参数等.有多种实现方式,在这里总结一下应用到的. URL与URI的区别 Uri - 统一资源标志符 Url - 统一 ...

  9. android so文件的作用,Android SO库

    查看手机CPU架构: $adb shell $cat /proc/cpuinfo OnePlus6: AArch64 Processor rev 12 (aarch64) ➜ ~ adb shell ...

最新文章

  1. 神经网络迭代次数与Lambert定律
  2. 三招看穿ERP软件是否可行
  3. DCMTK:创建,写入和读取二进制细分对象
  4. Matplotlib 中文用户指南 4.6 编写数学表达式
  5. Eclipse 插件开发 向导
  6. Bzoj 2127 happiness 最小割
  7. linux 系统 可视化工具实时监控_Linux上的实时监控平台-你需要这样做
  8. 分布式面试 - 如何基于 dubbo 进行服务治理、服务降级、失败重试以及超时重试?
  9. php如何复制一个对象,PHP中的对象复制及__clone() 函数
  10. 海豚的屠宰场--海豚湾
  11. 笨办法学 Linux 引言
  12. keepalived 非抢占模式
  13. 三种近距离通信技术(WIFI、蓝牙、NFC)
  14. pdffactory 打印字体_PdfFactory(虚拟打印机)
  15. python面板数据模型操作步骤_面板数据分析方法步骤全解
  16. 403forbidden提示没有权限
  17. (筆記) 如何在字串中從指定字元抓到指定字元(pointer版)? (C/C++) (C)
  18. 判断两条线段是否相交 java_判断两个线段是否相交02
  19. iOS 自定义转场动画篇
  20. linux的s权限和t权限

热门文章

  1. 联想v800手机看电子书的方法
  2. Excel中几个常见文本函数使用
  3. 解决windows7没有声音的问题
  4. 不安全的反序化基础原理(Insecure deserialization)
  5. 2022年新出的Python学习神器(附源码)
  6. tx1开发板可以装linux,Jetson TX1嵌入式开发板被Nvidia推出,发力深度学习
  7. Jetson TX1 刷机(20221107亲测教程)完整程度⭐⭐⭐⭐⭐避免踩坑
  8. Excel碰到空行无法筛选排序解决方法
  9. FreeType 简单使用
  10. dovecot MySQL配置_postfix+mysql+dovecot