iPhone アプリを Android に移植しようとしていますが、起動に問題があります。
データを取得するために次の関数があります。
public void onClick(View v) {
try{
//Toast.makeText(getApplicationContext(), "Starting update", Toast.LENGTH_SHORT).show();
progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");
new Thread() {
public void run() {
try{
DataManager manager = new DataManager(getApplicationContext());
manager.updateData();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error...");
alertDialog.setMessage(e.getMessage());
alertDialog.show();
}
progressDialog.dismiss();
}
}.start();
} catch (Exception e) {
Log.e(TAG, "Problem with getting the data: " + e.getMessage());
Toast.makeText(getApplicationContext(), "Error during update",
Toast.LENGTH_SHORT).show();
}
}
しかし、例外が発生すると、次のエラーが発生します (最初に AsyncTask を使用しようとしましたが、同じ問題に遭遇しました)。
08-29 20:23:24.389: ERROR/WindowManager(974): Activity org.idoms.iDomsAndroid.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412fcc38 that was originally added here
android.view.WindowLeaked: Activity org.idoms.iDomsAndroid.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412fcc38 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
at android.view.Window$LocalWindowManager.addView(Window.java:537)
at android.app.Dialog.show(Dialog.java:278)
at android.app.ProgressDialog.show(ProgressDialog.java:116)
at android.app.ProgressDialog.show(ProgressDialog.java:99)
at android.app.ProgressDialog.show(ProgressDialog.java:94)
at org.idoms.iDomsAndroid.MainActivity$1.onClick(MainActivity.java:46)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
これを行う正しい方法は何ですか?