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


相关推荐

  • maven中jar和war的区别

    maven中jar和war的区别jar文件包括java普通类、资源文件和普通文件,在maven中即是打包src/main/java和src/main/resources资源文件夹下的所有文件。在打包的时候会自动生成MATA-INF文件夹,用于存储maven的pom信息和MANIFEST.MF文件。例如:war文件包含全部的web应用程序,即所有的java类,配置信息和jsp、js等静态资源。但是需要注意war

    2022年5月23日
    79
  • 来自科学网博主的问候

    来自科学网博主的问候

    2021年8月24日
    52
  • FileZilla出现Failed to convert command to 8 bit charset 

    FileZilla出现Failed to convert command to 8 bit charset 

    2021年9月24日
    49
  • win10 卸载cuda10.1

    win10 卸载cuda10.1创建于:@2020.04.19修改于:@2020.04.19文章目录1.背景2.cuda卸载1.背景在尝试安装tensorflow-gpu时,cuda安装版本错误。需要卸载。2.cuda卸载(1)在控制面板中打开【程序】–>【程序和功能】(2)确定要卸载的内容,图中红框内的内容(3)删除C盘里面C:\ProgramFiles\NVIDIAGPUComputi…

    2022年6月16日
    32
  • 泰国80亿互联网记录数据库泄漏,疑遭黑客攻击[通俗易懂]

    泰国80亿互联网记录数据库泄漏,疑遭黑客攻击[通俗易懂]泰国最大的蜂窝网络AIS已使数据库脱机,疑遭黑客攻击,这使达80亿实时互联网记录泄漏到数百万泰国互联网用户上,该事件震惊整个泰国。全球著名白帽黑客、东方联盟创始人郭盛华博客文章中说,他在互联网上没有密码就找到了包含DNS查询和Netflow数据的数据库。通过访问该数据库,任何人都可以“快速描绘”互联网用户(或其家庭)的实时行为。他表示:“在数据库中找到的记录只能来自能够监视Internet流量在网络上流动的人。但是,没有一种简单的方法可以区分数据库是属于Internet提供商还…

    2022年9月15日
    3
  • 晴天的魔法乐园——谢尔宾斯基地毯(递归打印图形)「建议收藏」

    晴天的魔法乐园——谢尔宾斯基地毯(递归打印图形)「建议收藏」题目链接:https://judger.net/problem/1061ProblemDescription谢尔宾斯基地毯是一种分形图案,它的定义如下:令F(n)表示嵌套n层的谢尔宾斯基地毯,那么(下面的“空”均表示空格,仅为示意,实际输出时应仍为空格)当n=1时,F(1)为:空当n=2时,F(2)为:空空空空X空空空空一般地,如果F(n-1)表示嵌…

    2022年7月13日
    15

发表回复

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

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