Android StrictMode政策

Android StrictMode政策,第1张

概述遇到一些 Android应用程序的ANR问题所以我实现了StrictMode策略.从来没有使用过这个,希望有人可以帮助解释以下内容: 为什么日志显示2个违规,除了前4行和持续时间的差异外,看似相似?为什么还有2次违规 – 这是否意味着代码被执行了两次? 任何帮助赞赏 08-15 14:24:14.314: DEBUG/StrictMode(767): StrictMode policy viola 遇到一些 Android应用程序的ANR问题所以我实现了StrictMode策略.从来没有使用过这个,希望有人可以帮助解释以下内容:

为什么日志显示2个违规,除了前4行和持续时间的差异外,看似相似?为什么还有2次违规 – 这是否意味着代码被执行了两次?

任何帮助赞赏

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.access0(JobScheduleActivity.java:43)    at conx.ActivitIEs.JobScheduleActivity.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.access0(JobScheduleActivity.java:43)    at conx.ActivitIEs.JobScheduleActivity.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)
解决方法 StrictMode违规显示您正在UI线程上执行导致ANR问题的sqlite查询.

尝试在单独的线程上执行数据库交互,这将防止ANR问题并防止显示这些StrictMode违规.

从浏览LogCat输出看起来它在conx.ActivitIEs.JobScheduleActivity.onSaveEvent中出现

一些有用的阅读:

> http://developer.android.com/guide/components/processes-and-threads.html
> http://www.vogella.com/articles/AndroidPerformance/article.html

总结

以上是内存溢出为你收集整理的Android StrictMode政策全部内容,希望文章能够帮你解决Android StrictMode政策所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1124612.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存