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)
上一篇 2022年6月3日 上午7:36
下一篇 2022年6月3日 上午7:36


相关推荐

  • Android——进程间通信方式

    Android——进程间通信方式1 IntentActivi Service Receiver 都支持在 Intent 中传递 Bundle 数据 而 Bundle 实现了 Parcelable 接口 可以在不同的进程间进行传输 在一个进程中启动了另一个进程的 Activity Service 和 Receiver 可以在 Bundle 中附加要传递的数据通过 Intent 发送出去 可以看看 Android Bundle 浅析 2 文件共享 Windows 上 一个文件如果被加了排斥锁会导致其他线程无法对其进行访问 包括读和

    2026年3月17日
    2
  • Web前端性能优化——如何提高页面加载速度

    Web前端性能优化——如何提高页面加载速度

    2021年10月14日
    37
  • fuser详解

    fuser详解fuser 1 Linuxmanpage identifyproc 注释 fuser 找出使用指定文件或者 sockets 的进程 Synopsisfuse a s c 4 6 nspace k i signal muvf nam

    2026年3月19日
    4
  • 将menubar加入_java菜单栏工具栏

    将menubar加入_java菜单栏工具栏importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.util.EventListener;publicclassTestMenuBarextendsFrame/*implementsActionListener*/{MenuBarmenubar=newMenuBar();Menufi…

    2025年7月29日
    3
  • 从0开始学python_python37从零开始学

    从0开始学python_python37从零开始学如何用python进行期货程序化交易、程序化交易系统目前主要是通过计算机程序实现的,其实就是把交易者决策的过程用计算机语言描述出来,然后由计算机给出交易建议或直接发送交易指令到期货公司的。SDYGDFHFGJFGFTYKGHKTY你就是想找个软件或者券商的接口去上传交易指令,你前期的数据抓取和分析可能python都写好了,所以差这交易指令接口最后一步。对于股票的散户,正规的法子是华宝。国内量化交易…

    2022年10月8日
    5
  • hashmap扩容死锁简书_sql死锁

    hashmap扩容死锁简书_sql死锁HashMap扩容HashMap扩容transfer()函数原Entry数组转移到新Entry数组扩容死锁单线程扩容多线程扩容死锁HashMap扩容HashMap在JDK1.7使用的是数组+链表的方式,而在JDK1.8及以后则使用的是数组+链表+红黑树的方式进行数据存储。本文主要是对JDK1.7中存在的死锁问题进行分析。transfer()函数/***TransfersallentriesfromcurrenttabletonewTable.*/v

    2026年2月6日
    3

发表回复

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

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