こんにちは、進行状況ダイアログを表示しようとすると、不正なトークン ウィンドウ エラーが表示されます
以下は、AsyncTask を実行したアクティビティの onCreate 内のハンドラです。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = new ProgressDialog(getApplicationContext());
progress.setTitle(R.string.progress_title);
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.d("", "Handling callback");
super.handleMessage(msg);
position = (Position)msg.obj;
Toast.makeText(getApplicationContext(), position.getLattitude() + " " + position.getLongetude(),
Toast.LENGTH_LONG).show();
userLocation.stopSearchLocation();
FindRestaurants findRestaurants = new FindRestaurants();
findRestaurants.execute();
}
};
}
私の非同期タスク
class FindRestaurants extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// get users current location
progress.show(); //fails here
Log.d("", "onPreExecute");
if (position == null) {
position = userLocation.getLastKnownLocation();
Log.d("", "position = " + position.getLattitude() + " " + position.getLongetude());
}
// find upper and lower boundaries
Log.d("", "position outside of condition= " + position.getLattitude() + " " + position.getLongetude());
super.onPreExecute();
}
完全なスタック トレース
03-28 14:40:02.314: E/AndroidRuntime(13658): FATAL EXCEPTION: main
03-28 14:40:02.314: E/AndroidRuntime(13658): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.view.ViewRoot.setView(ViewRoot.java:532)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.app.Dialog.show(Dialog.java:241)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.app.ProgressDialog.show(ProgressDialog.java:107)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.app.ProgressDialog.show(ProgressDialog.java:90)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.app.ProgressDialog.show(ProgressDialog.java:85)
03-28 14:40:02.314: E/AndroidRuntime(13658): at com.jr.haliotest.MainActivity$FindRestaurants.onPreExecute(MainActivity.java:61)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.os.AsyncTask.execute(AsyncTask.java:391)
03-28 14:40:02.314: E/AndroidRuntime(13658): at com.jr.haliotest.MainActivity$1.handleMessage(MainActivity.java:138)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.os.Looper.loop(Looper.java:130)
03-28 14:40:02.314: E/AndroidRuntime(13658): at android.app.ActivityThread.main(ActivityThread.java:3835)
03-28 14:40:02.314: E/AndroidRuntime(13658): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 14:40:02.314: E/AndroidRuntime(13658): at java.lang.reflect.Method.invoke(Method.java:507)
03-28 14:40:02.314: E/AndroidRuntime(13658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-28 14:40:02.314: E/AndroidRuntime(13658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-28 14:40:02.314: E/AndroidRuntime(13658): at dalvik.system.NativeStart.main(Native Method)