ProgressDialog在扩展AsyncTask中

时间:2013-04-19 19:04:05

标签: android progressdialog

我需要在扩展AsyncTask中显示ProgressDialog ...但是......

public class TareaAsincrona extends AsyncTask<Void, Void, Void> { 
    protected void onPreExecute() 
    { 
        pdialog = new ProgressDialog(Principal.this); 
        pdialog.setMessage("Wolas"); 
        pdialog.setIndeterminate(true); 
        pdialog.setCancelable(false); 
        pdialog.show(); 
        } 
    protected void onPostExecute() 
    { pdialog.dismiss(); } 

    protected Void doInBackground(Void... params) { .... .... } //// //// } 
}

logcat的

04-19 14:59:40.844: E/dalvikvm(21264): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-19 14:59:41.434: E/WindowManager(21264): Activity dsm.transporte_ordtra.Principal has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4165d0a0 that was originally added here
04-19 14:59:41.434: E/WindowManager(21264): android.view.WindowLeaked: Activity dsm.transporte_ordtra.Principal has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4165d0a0 that was originally added here
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
04-19 14:59:41.434: E/WindowManager(21264):     at android.app.Dialog.show(Dialog.java:278)
04-19 14:59:41.434: E/WindowManager(21264):     at dsm.transporte_ordtra.Principal$TareaAsincrona.onPreExecute(Principal.java:211)
04-19 14:59:41.434: E/WindowManager(21264):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
04-19 14:59:41.434: E/WindowManager(21264):     at android.os.AsyncTask.execute(AsyncTask.java:511)
04-19 14:59:41.434: E/WindowManager(21264):     at dsm.transporte_ordtra.Principal$3.onClick(Principal.java:145)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.View.performClick(View.java:3511)
04-19 14:59:41.434: E/WindowManager(21264):     at android.view.View$PerformClick.run(View.java:14105)
04-19 14:59:41.434: E/WindowManager(21264):     at android.os.Handler.handleCallback(Handler.java:605)
04-19 14:59:41.434: E/WindowManager(21264):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-19 14:59:41.434: E/WindowManager(21264):     at android.os.Looper.loop(Looper.java:137)
04-19 14:59:41.434: E/WindowManager(21264):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-19 14:59:41.434: E/WindowManager(21264):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 14:59:41.434: E/WindowManager(21264):     at java.lang.reflect.Method.invoke(Method.java:511)
04-19 14:59:41.434: E/WindowManager(21264):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-19 14:59:41.434: E/WindowManager(21264):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-19 14:59:41.434: E/WindowManager(21264):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

您正在预先执行

访问您的活动
pdialog = new ProgressDialog(Principal.this); 
例如,你可以在你的类中声明pdialog并在里面使用它,已经初始化了。

class TareaAsincrona{
    ProgressDialog instancedProgressDialog;

    public TareaAsincrona (ProgressDialog  instancedProgressDialog){
       myProgressDialog = instancedProgressDialog;
    }
    //Your code continues here....

}