2014-07-09 42 views
-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) 

任何想法,为什么谢谢你在前进。

+0

u能PLZ张贴EventBus.getBus()代码 – KOTIOS

+0

注释nextConf.show();并再次运行,那么你可以找到真正的问题。问题可能在于此EventBus.getBus()。post(new MainActivity.ConferenceSwitchRequestEvent()); –

+0

嗨,莫娜!当然,这是我的EventBus.get()代码:public final class EventBus { \t private static Bus sBus = new Bus(); \t public static Bus getBus(){ \t \t return sBus; \t} } –

回答

0

由于受保护的虚函数doInBackground(Void ... result)导致崩溃EventBus.getBus()。post(new MainActivity.ConferenceSwitchRequestEvent()); 无效进展; 返回null;

返回null

相关问题