私は ACRA を使用して数週間アプリを運用していますが、今日 1 つの奇妙なエラーが報告されるまでエラーはありませんでした。
私が持っている:
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
スタック トレースのこのメソッドから取得されます (再トレース):
at my.app.CountdownFragment$1.void onPostExecute(java.lang.Object)(SourceFile:1)
そして、これは関連するソース スニペットです。
private void addInstructionsIfNeeded() {
if (S.sDisplayAssist) {
new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
return null;
}
/*
* runs on the ui thread
*/
protected void onPostExecute(String result) {
Activity a = getActivity();
if (S.sHelpEnabled && a != null) {
in = new InstructionsView(a.getApplicationContext());
RelativeLayout mv = (RelativeLayout) a
.findViewById(R.id.main_place);
mv.addView(in.prepareView());
}
};
}.execute("");
}
}
addInstructionsIfNeeded()
ハンドラーがディスパッチしたメッセージ (UI スレッド) から呼び出される場所。
onPostExecute()
UIスレッドで実行されるのに、なぜ「間違ったスレッド」になったのですか?- このコードはすでに 150 を超えるデバイスで実行され、(Flurry によると) 100000 回以上実行されましたが、このエラーは発生しませんでした。
- 元のデバイスは、SDK 4.0.4 を実行する Samsung SGH-I997 です。
私の質問は次のとおりです。
編集:これはすべてフラグメントで発生します