AsyncTaskを開始し、操作中に進行状況ダイアログを表示するアクティビティがあります。アクティビティは、回転またはキーボードスライドによって再作成されないと宣言されています。
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
</intent-filter>
</activity>
タスクが完了したら、ダイアログを閉じますが、一部の電話(フレームワーク:1.5、1.6)では、このようなエラーがスローされます。
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:356)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:201)
at android.view.Window$LocalWindowManager.removeView(Window.java:400)
at android.app.Dialog.dismissDialog(Dialog.java:268)
at android.app.Dialog.access$000(Dialog.java:69)
at android.app.Dialog$1.run(Dialog.java:103)
at android.app.Dialog.dismiss(Dialog.java:252)
at xxx.onPostExecute(xxx$1.java:xxx)
私のコードは:
final Dialog dialog = new AlertDialog.Builder(context)
.setTitle("Processing...")
.setCancelable(true)
.create();
final AsyncTask<MyParams, Object, MyResult> task = new AsyncTask<MyParams, Object, MyResult>() {
@Override
protected MyResult doInBackground(MyParams... params) {
// Long operation goes here
}
@Override
protected void onPostExecute(MyResult result) {
dialog.dismiss();
onCompletion(result);
}
};
task.execute(...);
dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
task.cancel(false);
}
});
dialog.show();
私が読んだもの(http://bend-ing.blogspot.com/2008/11/properly-handle-progress-dialog-in.html)から見て、Androidソースで見て、それを取得する唯一の可能な状況のようです例外は、アクティビティが破棄された場合です。しかし、私が述べたように、私は基本的なイベントのための活動のレクリエーションを禁止します。
だから、どんな提案も大歓迎です。