严格模式+分析

Mik*_*rer 7 android android-strictmode

我正在使用Google Analytics for Android,但在启用StrictMode后,我收到了很多这样的消息:

 StrictMode policy violation; ~duration=349 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
 at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:745)
 at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
 at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235)
 at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189)
 at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1309)
 at com.google.android.apps.analytics.PersistentEventStore.peekEvents(Unknown Source)
 at com.google.android.apps.analytics.PersistentEventStore.peekEvents(Unknown Source)
 at com.google.android.apps.analytics.GoogleAnalyticsTracker.dispatch(Unknown Source)
 at com.google.android.apps.analytics.GoogleAnalyticsTracker$1.run(Unknown Source)
 at android.os.Handler.handleCallback(Handler.java:587)
 at android.os.Handler.dispatchMessage(Handler.java:92)
 at android.os.Looper.loop(Looper.java:123)
 at android.app.ActivityThread.main(ActivityThread.java:3647)
 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:839)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

我可以忽略吗?我还尝试将tracker.trackingPageView(...)放入AsyncTask - 相同的结果.

以下是我对StrictMode的设置:

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    .detectDiskReads()
    .detectDiskWrites()
    .detectNetwork()
    .penaltyLog()
    .build());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
        .detectLeakedSqlLiteObjects()
    .penaltyLog()
    .penaltyDeath()
    .build());
Run Code Online (Sandbox Code Playgroud)

我真的很感激任何帮助 - 提前感谢!麦克风

Kev*_*oil 6

查看iosched应用程序的AnalyticsUtils.java,它可以在跟踪调用中做一些asynctask魔术.但是在构造函数中有这个:

    // Unfortunately this needs to be synchronous.
    mTracker.start(UACODE, 300, mApplicationContext);
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,这并不能解决我的问题.所有调用都是在非UI线程中进行的,但我仍然看到StrictMode抱怨,因为库仍然访问Handler内部的一些SQLite数据库(< - 在UI线程中).:( (2认同)