asynctask の実行中にユーザーにスピナーを表示する必要があります。
public class RecoverListTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog spinner;
private Context context;
public RecoverListTask(Context c) {
context = c;
spinner = new ProgressDialog(context); // spinner
}
@Override
protected void onPreExecute() {
// show progress spinner
spinner.setMessage("Downloading Podcats List");
spinner.show();
//do something
}
@Override
protected void onPostExecute(Void v) {
spinner.dismiss();
}
}
(私はスピナーに関する部分だけを貼り付けました)しかし、アプリを実行しようとすると、次のエラーが発生します:
11-05 18:02:49.077: E/WindowManager(28986): Activity com.example.podcast610downloader.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4264ef28 V.E..... R....... 0,0-684,192} that was originally added here
11-05 18:02:49.077: E/WindowManager(28986): android.view.WindowLeaked: Activity com.example.podcast610downloader.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4264ef28 V.E..... R....... 0,0-684,192} that was originally added here
11-05 18:02:49.077: E/WindowManager(28986): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
11-05 18:02:49.077: E/WindowManager(28986): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
11-05 18:02:49.077: E/WindowManager(28986): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.Dialog.show(Dialog.java:281)
11-05 18:02:49.077: E/WindowManager(28986): at com.example.podcast610downloader.RecoverListTask.onPreExecute(RecoverListTask.java:31)
11-05 18:02:49.077: E/WindowManager(28986): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
11-05 18:02:49.077: E/WindowManager(28986): at android.os.AsyncTask.execute(AsyncTask.java:534)
11-05 18:02:49.077: E/WindowManager(28986): at com.example.podcast610downloader.MainActivity.onCreate(MainActivity.java:24)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.Activity.performCreate(Activity.java:5133)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-05 18:02:49.077: E/WindowManager(28986): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 18:02:49.077: E/WindowManager(28986): at android.os.Looper.loop(Looper.java:137)
11-05 18:02:49.077: E/WindowManager(28986): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-05 18:02:49.077: E/WindowManager(28986): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 18:02:49.077: E/WindowManager(28986): at java.lang.reflect.Method.invoke(Method.java:525)
11-05 18:02:49.077: E/WindowManager(28986): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-05 18:02:49.077: E/WindowManager(28986): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-05 18:02:49.077: E/WindowManager(28986): at dalvik.system.NativeStart.main(Native Method)
onCreate コード:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//recover list of available podcast (with details)
RecoverListTask task = new RecoverListTask(this);
task.execute(null, null, null);
listView = (ListView) findViewById(R.id.listView);
arrayAdapter=new ArrayAdapter<PodcastFile>(this, android.R.layout.simple_list_item_1);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
});
}
どうしたの?