我正在使用 AsyncTask 收集数据,然后开始一个新活动,但我得到了一个泄露的窗口。
class GetDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute()
{
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage("Getting schedule for "+selectedSport+"...");
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params)
{
XmlPullFeedParser xpfp = new XmlPullFeedParser(scheduleURLtoGet);
ArrayList<Event> allEvents = xpfp.getEvents();
scheduleToPassAlong = allEvents.toArray(new Event[allEvents.size()]);
return null;
}
@Override
protected void onPostExecute(Void res)
{
mProgressDialog.dismiss();
startScheduleActivity();
}
}
private void startScheduleActivity(){
Intent intent = new Intent(this, ScheduleBoard.class);
intent.putExtra(SPORT_NAME_EXTRA, selectedSport);
intent.putExtra(SCHEDULE_FOR_SPORT_EXTRA, scheduleToPassAlong);
startActivity(intent);
}
异常似乎发生在 ScheduleBoard 活动中,但 doInBackground 中的过程未完成。
这是堆栈,我仍然无法弄清楚发生了什么。我在 doInBackground 中有 try/catch,但没有触发任何内容:
07-31 19:48:18.667: E/WindowManager(2866): Activity com.myproj.activities.ScheduleBoard has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40557718 that was originally added here
07-31 19:48:18.667: E/WindowManager(2866): android.view.WindowLeaked: Activity com.myproj.activities.ScheduleBoard has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40557718 that was originally added here
07-31 19:48:18.667: E/WindowManager(2866): at android.view.ViewRoot.<init>(ViewRoot.java:263)
07-31 19:48:18.667: E/WindowManager(2866): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
07-31 19:48:18.667: E/WindowManager(2866): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
07-31 19:48:18.667: E/WindowManager(2866): at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.Dialog.show(Dialog.java:241)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.AlertDialog$Builder.show(AlertDialog.java:810)
07-31 19:48:18.667: E/WindowManager(2866): at com.myproj.activities.ScheduleBoard.displayNoStoriesMessageAndExit(ScheduleBoard.java:114)
07-31 19:48:18.667: E/WindowManager(2866): at com.myproj.activities.ScheduleBoard.populateTable(ScheduleBoard.java:62)
07-31 19:48:18.667: E/WindowManager(2866): at com.myproj.activities.ScheduleBoard.onCreate(ScheduleBoard.java:56)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-31 19:48:18.667: E/WindowManager(2866): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 19:48:18.667: E/WindowManager(2866): at android.os.Looper.loop(Looper.java:130)
07-31 19:48:18.667: E/WindowManager(2866): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-31 19:48:18.667: E/WindowManager(2866): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 19:48:18.667: E/WindowManager(2866): at java.lang.reflect.Method.invoke(Method.java:507)
07-31 19:48:18.667: E/WindowManager(2866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-31 19:48:18.667: E/WindowManager(2866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-31 19:48:18.667: E/WindowManager(2866): at dalvik.system.NativeStart.main(Native Method)