android strictmode有什么作用,Android StrictMode policy

android strictmode有什么作用,Android StrictMode policy问题RunningintosomeANRissueswithanandroidapplicationsoIimplementedtheStrictModepolicies.Neverusedthisbeforesohopefullysomeonecanhelpexplainthefollowing:Whydoesthelogshow2…

大家好,又见面了,我是你们的朋友全栈君。

问题

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/136754.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 苹果怎么测试真机_iphone7plus验机步骤

    苹果怎么测试真机_iphone7plus验机步骤1、点击左上角菜单Xcode->Preferences。2、在跳出来的小窗口页面的左下角,点击加号添加苹果id。3、在账号密码输入完毕后,点击小窗口右下角的viewdetails或者双击右下角自己的id账号。然后把IOSdevelopment点击create至选中态。如图:4、将设备通过数据线连接Mac(手机弹出窗口时,选择信任此电脑)5、此时在设备列表上应该能看…

    2022年9月3日
    2
  • kindeditor php配置,KindEditor-编辑器配置参数属性 | 小灰灰博客

    kindeditor php配置,KindEditor-编辑器配置参数属性 | 小灰灰博客在《开发php接入富文本编辑器KindEditor》中提到了KindEditor编辑器的使用方法,通过使用KE.show(config)方法即可将编辑器添加到文档中。·无论使用哪种方式使用KindEditor编辑器,都必须进行参数配置;·可以在KE.show()和KE.init()方法中传递配置参数config;·配置参数config是一个对象,一般使用字面量对象;·其中,id参数是唯一必须进行配…

    2022年10月12日
    0
  • Hbase面试题(面经)整理

    Hbase面试题(面经)整理1.Hbase是什么?hbase的特点是什么?Hbase一个分布式的基于列式存储的数据库,基于Hadoop的hdfs存储,zookeeper进行管理。 Hbase适合存储半结构化或非结构化数据,对于数据结构字段不够确定或者杂乱无章很难按一个概念去抽取的数据。 Hbase为null的记录不会被存储。 基于的表包含rowkey,时间戳,和列族。新写入数据时,时间戳更新,同…

    2022年5月31日
    31
  • PHY芯片lan8720调试笔记_工业以太网接口芯片

    PHY芯片lan8720调试笔记_工业以太网接口芯片1、LAN8720A简介2、芯片管脚配置3、硬件电路

    2022年4月19日
    127
  • 大数据技术大致包含哪些内容「建议收藏」

    大数据技术大致包含哪些内容「建议收藏」关于大数据的概念,指的是无法在一定时间内用常规软件工具对其内容进行抓取、管理和处理的数据集合。而大数据技术,是指从各种各样类型的数据中,快速获得有价值信息的能力。那么关于大数据的技术大致包含哪些内容?一、数据采集ETL工具负责将分布的、异构数据源中的数据如关系数据、平面数据文件等抽取到临时中间层后进行清洗、转换、集成,最后加载到数据仓库或数据集市中,成为联机分析处理、数据挖掘的基础。二…

    2022年5月28日
    40
  • nmap命令小结(一)

    nmap命令小结(一)Nmapnmap是一个非常强大的网络扫描工具,学习nmap的话,我建议大家多读一读官方文档,这里我所写的也仅仅是对Nmap中文文档的一个总结,以及一些我的个人看法。官方文档地址:http://www.nmap.com.cn/主机发现端口扫描主机发现nmap的主机发现主要是基于ICMP包的一个探测,所以用nmap的主机发现命令格式大多都是-P*;-sP:nmap仅对主机进行ping扫

    2022年5月8日
    36

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号