2

Strict モードをセットアップしてから、Bugsense ハンドラーをセットアップしました。これにより、StrictMode ポリシー違反が発生しました。

なぜそれが起こるのか論理的な説明はありますか?どうすればそれを取り除くことができますか?

MyApplication.java:

    android.os.StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new android.os.StrictMode.ThreadPolicy.Builder();
    android.os.StrictMode.VmPolicy.Builder vmPolicyBuilder = new android.os.StrictMode.VmPolicy.Builder();
    android.os.StrictMode.setThreadPolicy(threadPolicyBuilder.detectAll().penaltyLog().build());
    android.os.StrictMode.setVmPolicy(vmPolicyBuilder.detectAll().penaltyLog().build());

    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {

                BugSenseHandler.initAndStartSession(MyApplication.this, "my-id");

            return null;
        }
    }.execute();

スタック:

01-21 09:43:40.889: D/StrictMode(29660): StrictMode policy violation: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
01-21 09:43:40.889: D/StrictMode(29660):    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:745)
01-21 09:43:40.889: D/StrictMode(29660):    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:228)
01-21 09:43:40.889: D/StrictMode(29660):    at java.io.FileInputStream.<init>(FileInputStream.java:80)
01-21 09:43:40.889: D/StrictMode(29660):    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:381)
01-21 09:43:40.889: D/StrictMode(29660):    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
01-21 09:43:40.889: D/StrictMode(29660):    at com.bugsense.trace.BugSenseHandler.initAndStartSession(Unknown Source)
01-21 09:43:40.889: D/StrictMode(29660):    at com.bugsense.trace.BugSenseHandler.initAndStartSession(Unknown Source)
01-21 09:43:40.889: D/StrictMode(29660):    at my.app$1.doInBackground(MyApplication.java:52)
01-21 09:43:40.889: D/StrictMode(29660):    at my.app$1.doInBackground(MyApplication.java:1)
01-21 09:43:40.889: D/StrictMode(29660):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-21 09:43:40.889: D/StrictMode(29660):    at java.lang.Thread.run(Thread.java:1019)
4

3 に答える 3

2

you get this error because the plugin reads information from the SharedPreferences in the main thread.

Unfortunately for the moment there is no way to get over this, except for lowering the policy of the Strict mode.

We are working on this and the next version of the BugSense plugin that will be released soon will be working great with Strict Mode.

Thank you for your feedback, it's very valuable, if you have any other question I will be happy to answer it at our support forums!

于 2013-01-22T11:34:27.360 に答える
0

BugSense SDK (3.2) の新しいリリースを試しましたか? Strict Mode の問題を修正しました。

ここで変更ログを確認してください。

于 2013-01-29T09:47:58.397 に答える
-2

同様の問題がありました。アプリ用に DEVELOPER_MODE を作成しました。私が開発者モードにあるかどうかをアプリに伝えるのは、ブール値のフラグです。開発者モードでのみ strictmode を有効にします。公開アプリで strictmode を有効にする理由はありません。一方、開発者モードではバグセンスを無効にしています。なぜなら、LogCat でバグ レポートが表示された場合、バグ レポートは必要ないからです。私のコードは次のようになります

public static final boolean DEVELOPER_MODE = true;


@Override
public void onCreate() {

    if (DEVELOPER_MODE) {
    StrictMode.setThreadPolicy(new  StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    StrictMode.setVmPolicy(new  StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());

    }else{
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {

                BugSenseHandler.initAndStartSession(MyApplication.this, "my-id");

            return null;
            }
        }.execute();
    }
}
于 2013-01-24T09:15:55.163 に答える