7

I am using Google Analytics for Android but after turning on StrictMode I get a lot of message like this:

 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)

Can I ignore that? I also tried to put tracker.trackingPageView(...) into AsyncTask - same Result.

Here are my settings for StrictMode:

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

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
        .detectLeakedSqlLiteObjects()
    .penaltyLog()
    .penaltyDeath()
    .build());

I would really appreciate any help - thanks in advance! Mike

Mike Mitterer
  • 6,810
  • 4
  • 41
  • 62
  • I had the same problem recently. I could get around all the events I was actually creating, like trackPageView, but using my own Handler or AsyncTask (though it seems like the mobile API should have already handled that), but since I'm not controlling dispatch, I couldn't address that one. I think it's just a live with it for now thing. I don't know where to report this either, since the mobile analytics SDK is a "labs" project at present. – Charlie Collins Jun 15 '11 at 17:07

2 Answers2

6

Check out the iosched app for their AnalyticsUtils.java which does some asynctask magic around track calls. There is however this in the constructor:

    // Unfortunately this needs to be synchronous.
    mTracker.start(UACODE, 300, mApplicationContext);
pevik
  • 4,523
  • 3
  • 33
  • 44
Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
  • 2
    Unfortunately this doesn't solve the issue for me. All the calls are made in a non UI thread, but I still see StrictMode complaining, because the library still accesses some SQLite db inside a Handler (<- in the UI thread). :( – BoD Jul 02 '12 at 16:03
4

Can I ignore that?

You probably do not have a choice but to ignore that, and hope that the Analytics team improves their code someday.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491