-2
我有一個按鈕,onClick方法中我有一個事件(請求)。我正在使用AsyncTasc在處理請求時顯示proggressDialog。問題是當我點擊按鈕,我得到progressDialog,幾秒鐘後,應用程序崩潰。 這裏是我的代碼:如果我使用AsyncTask,ProgressDialiog會崩潰應用程序?
joinButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>(){
@Override
protected void onPreExecute() {
super.onPreExecute();
nextConf = new ProgressDialog(mContext);
nextConf.setMessage("message");
nextConf.setProgressStyle(ProgressDialog.STYLE_SPINNER);
nextConf.setCancelable(false);
nextConf.show();
}
@Override
protected Void doInBackground(Void... params) {
EventBus.getBus().post(new MainActivity.ConferenceSwitchRequestEvent());
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
nextConf.dismiss();
};
}.execute();
}
});
}
return view;
,這些都是崩潰日誌:
01/com.xxx.xxx E/WindowManager﹕ android.view.WindowLeaked: Activity com.xxx.xxx.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42c8ad68 V.E..... R......D 0,0-1061,288} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:462)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:267)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:289)
at com.xxx.xxxx.ConferenceMembersListAdapter$1$1.onPreExecute(ConferenceMembersListAdapter.java:141)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at com.xxx.xxx.ConferenceMembersListAdapter$1.onClick(ConferenceMembersListAdapter.java:133)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19421)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
任何想法,爲什麼謝謝你在前進。
u能PLZ張貼EventBus.getBus()代碼 – KOTIOS
註釋nextConf.show();並再次運行,那麼你可以找到真正的問題。問題可能在於此EventBus.getBus()。post(new MainActivity.ConferenceSwitchRequestEvent()); –
嗨,莫娜!當然,這是我的EventBus.get()代碼:public final class EventBus { \t private static Bus sBus = new Bus(); \t public static Bus getBus(){ \t \t return sBus; \t} } –