4

What i am trying to do is to get files from server. The same code is running f9 with sdcard but when i get files from thorugh thread then i am getting following error in my logcat.

My code is as follows:

public class Map extends Activity
{
   //
    private GraphicsView mGLView;

    //private GisGLRenderer m_GisRenderer;

    final static String RESULT_KEY="result";
    final static int REQ_CODE=1001;
     AlertDialog m=null;



    public class LoadFile  extends AsyncTask<String,String,String>
    {
        ProgressDialog Asycdialog = new ProgressDialog(Map.this);


        @Override
        protected void onPreExecute() {
            //set message of the dialog
            Asycdialog.setMessage("Loading File");
            Asycdialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            //show dialog
            Asycdialog.show();
            super.onPreExecute();
        }

        protected void onProgressUpdate(String ... progress)
        {

        }

        protected String  doInBackground(String ... Params)
        {
            Map.this.mGLView.LoadProjectFile(AppFuncs.g_path);
            Map.this.mGLView.requestRender();
            return null;
        }
        protected void onPostExecute(String result)
        {
            Asycdialog.dismiss();

            super.onPostExecute(result);
           }
    }




    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        mGLView =  (GraphicsView) findViewById(R.id.glview);


    }
  public void bt_Open(View v)
    {

        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setTitle("Load File");
        builder.setMessage("Choose an option to load file")
                .setCancelable(false)
                .setNegativeButton("Server",new DialogInterface.OnClickListener(){
                   public void onClick(DialogInterface dialog,int which)
                   {
                       Intent i= new Intent(Map.this,serv.class);
                       startActivityForResult(i,REQ_CODE);

                   }

                }

                )
                .setPositiveButton("SDcard",new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int which)
                    {

                        Intent i= new Intent(Map.this,FileChooser.class);
                        startActivityForResult(i,REQ_CODE);

                    }

                }

                );

        final AlertDialog a=builder.create();
        a.show();

}
 protected void onActivityResult(int requestCode, int resultCode,Intent data)
    {
        //super.onActivityResult(requestCode,resultCode,data);
        if(requestCode==REQ_CODE)
        {
            if(resultCode==RESULT_OK && data.getExtras().containsKey(RESULT_KEY))
            {

            //    Toast.makeText(this,data.getExtras().getString(RESULT_KEY),Toast.LENGTH_SHORT).show();
           //     this.mGLView.m_SelectedProjectPath =  AppFuncs.path;

                LoadFile f= new LoadFile();
                f.execute("");


             //   this.mGLView.LoadProjectFile(AppFuncs.path);
            }
        }
    }







ERROR/WindowManager(20040): Activity idtech.ESDN.Map has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416a97b0 that was originally added here
        android.view.WindowLeaked: Activity idtech.ESDN.Map has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416a97b0 that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:380)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
        at 

android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
        at android.view.Window$LocalWindowManager.addView(Window.java:547)
        at android.app.Dialog.show(Dialog.java:277)
        at idtech.ESDN.Map$LoadFile.onPreExecute(Map.java:59)
        at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
        at android.os.AsyncTask.execute(AsyncTask.java:534)
        at idtech.ESDN.Map.onActivityResult(Map.java:221)
        at android.app.Activity.dispatchActivityResult(Activity.java:5194)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3180)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3227)
        at android.app.ActivityThread.access$1100(ActivityThread.java:137)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4838)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
        at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

16

发生这种情况的原因是:

Dialog退出活动后,您正试图显示 a 。

解决方案 :

dismiss()Dialog退出之前调用您创建的Activity,例如在 onPause() 中。离开前应关闭所有窗口和对话框Activity

于 2013-08-20T08:50:10.607 回答
4

在显示之前检查Activity是否未完成,Dialog否则可能会泄漏:

    if(!this.isFinishing()){
        dialog.show();
    }

还尝试将此声明移动到Activity, 而不是, 并尝试在活动中AsyncTask解散。DialogonDestroy

    ProgressDialog Asycdialog = new ProgressDialog(Map.this);
于 2013-08-20T08:44:51.053 回答