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


相关推荐

  • Java Calendar获取年、月、日、时间[通俗易懂]

    Java Calendar获取年、月、日、时间[通俗易懂]Calendarc=Calendar.getInstance(TimeZone.getTimeZone(“GMT+08:00”));//获取东八区时间intyear=c.get(Calendar.YEAR);//获取年intmonth=c.get(Calendar.MONTH)+1;//获取月份,0表示1月份intday=c.get(Calend…

    2022年5月2日
    43
  • java readwritelock原理_java四种线程池

    java readwritelock原理_java四种线程池前言前面介绍了java中排它锁,共享锁的底层实现机制,本篇再进一步,学习非常有用的读写锁。鉴于读写锁比其他的锁要复杂,不想堆一大波的文字,本篇会试图图解式说明,把读写锁的机制用另外一种方式阐述。

    2022年8月12日
    8
  • Java 编码问题

    Java 编码问题

    2021年10月7日
    38
  • 语义分割性能指标_语义分割评价指标

    语义分割性能指标_语义分割评价指标文章目录语义分割的评价指标IoUorIU(intersectionoverunion)语义分割的评价指标在整理评价指标之前,先补充一下预备知识。我们在进行语义分割结果评价的时候,常常将预测出来的结果分为四个部分:truepositive,falsepositive,truenegative,falsenegative,其中negative就是指非物体标签的部分(可以直接理解为…

    2022年8月21日
    7
  • flowable流程详解

    flowable流程详解flowable图例解释请假流程bpmn20.xml文件请假流程示例图例解释开始事件:图中用细线圆圈来表示,是流程实例的开始点箭头:表示节点之间的流转指向。用户任务:在图中用左上角有人的圆角矩形表示,这些是需要用户来操作的节点。图中有两个,第一个表示需要经理进行审批来同意或拒绝,第二个表示用户来确认销假。排它网关:用叉形符号填充的菱形表示,从该图中出来的箭头往往有多个,但只有一个满足条件,流程会沿着满足条件的方向流转。自动化任务:左上角有齿轮形状的的圆角矩形,表示自动执行的节点。图中

    2022年5月11日
    316
  • ffmpeg hevc_ffmpeg视频解码

    ffmpeg hevc_ffmpeg视频解码本次目标:1)将容器中的音频码流和视频码流分离出来。2)针对mp4文件中的码流情况进行修复。解封装的基本过程:#include<stdio.h>#include”libavcodec/avcodec.h”#include”libavformat/avformat.h”//MPEG-TS文件解封装得到的码流可播放,MP4解封装得到的码流不可播放;//这与容器的封装方式有关。voiddemuxer(constchar*url){//初始化格式上下文

    2022年10月16日
    2

发表回复

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

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