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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 用户自定义类加载器下载_spring类加载器顺序

    用户自定义类加载器下载_spring类加载器顺序在Java的日常应用程序开发中,类的加载几乎是由上述3种类加载器相互配合执行的,在必要时,我们还可以自定义类加载器,来定制类的加载方式。为什么要自定义类加载器?隔离加载类 修改类加载的方式 扩展加载源 防止源码泄漏用户自定义类加载器实现步骤:开发人员可以通过继承抽象类ava.1ang.ClassLoader类的方式,实现自己的类加载器,以满足一些特殊的需求 在JDK1.2之前,在自定义类加载器时,总会去继承ClassLoader类并重写1oadClass()方法,从而实现自定义的类加载类

    2022年9月3日
    2
  • TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别

    TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别我的TLS实现:https://github.com/mrpre/atls/大家可以参考,代码里面的逻辑较清晰。我的SSL专栏见:https://blog.csdn.net/mrpre/article/category/9270159描述了TLS的各方面。本文是对前面系列章节关于非对称算法在SSL中运用的总结和细化,但也可以作为详解SSL中RSA、ECDHE非对…

    2022年5月5日
    149
  • Java中数字的四舍五入和取整

    Java中数字的四舍五入和取整Java中对数字进行四舍五入或取整处理经常使用Math库中的三个方法:ceilfloorround1ceil向上取整ceil英文释义:天花板。天花板在上面,所以是向上取整,好记了。Math.ceil函数接收一个double类型的参数,用于对数字进行向上取整(遇小数进1),即返回一个大于或等于传入参数的最小整数(但还是以double类型返回)。2floor向下取整floor英文释义:地板。地板在下面,所以是向下取整,好记了。Math.floor函数接收一个double

    2022年7月7日
    20
  • JavaScript中数组Array方法详解[通俗易懂]

    JavaScript中数组Array方法详解[通俗易懂]ECMAScript3在Array.prototype中定义了一些很有用的操作数组的函数,这意味着这些函数作为任何数组的方法都是可用的。1、Array.join()方法Array.join()方

    2022年7月4日
    16
  • touchstart和click 自动区分

    touchstart和click 自动区分varclickEvent=(function(){if(‘ontouchstart’indocument.documentElement===true)return’touchstart’;elsereturn’click’;})();转载于:https://www.cnblogs.com/gaidalou/p/9927885.html

    2022年6月19日
    24
  • python中的pop函数和append函数

    python中的pop函数和append函数pop()函数1、描述pop()函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值。语法pop()方法语法:list.pop(obj=list[-1])2、参数obj–可选参数,要移除列表元素的对象。3、返回值该方法返回从列表中移除的元素对象。4、实例以下实例展示了pop()函数的使用方法:#!/usr/bin/pythonaList=[123,’xyz’,’z

    2022年6月29日
    24

发表回复

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

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