Android Error: Window Leaked in AsyncTask

Katherine99

I have only sometimes an error which says Activity com.prueba.omnibus.EspacialTecnico has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41e794a0 that was originally added here This happens when the activity finishes and an asynctask function is executed. I have searched but I have no idea what the problem could be.

Action that is doen when the user clicks "finish" and the error happens.

protected Dialog onCreateDialog(int id) {
    super.onCreateDialog(id);
    switch (id) {
    case (int) DIALOG_ALERT_SALIR:
        return new AlertDialog.Builder(this)
                .setIcon(R.drawable.icon_warning)
                .setTitle(R.string.warning)
                .setMessage(R.string.confsalir)
                .setPositiveButton(R.string.alert_dialog_ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                if (batteryReceiver == null){   
                                }
                                else{
                                    try{
                                        unregisterReceiver(batteryReceiver);
                                    }catch(IllegalArgumentException iae){
                                    }
                                    batteryReceiver = null;
                                }           



                               Correccion();
                               Parseo();
                               reloj.cancel();
                               if (Titulacion.IsReachable1(getApplicationContext())){
                                new CreateResultados().execute();


                                }
                               EspacialTecnico.this.finish();
                               try {
                                    XMLResumen.escribirXMLResume();
                                } catch (FileNotFoundException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }}


                       })
                .setNegativeButton(R.string.alert_dialog_cancel,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {

                            }
                        })

                .create();
    }

    return null;

}

Asynctask Function Could the error be produced by the dialog?

class CreateResultados extends AsyncTask<String, String, String> {


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(EspacialTecnico.this);
            pDialog.setMessage("Transfiriendo...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }


        protected String doInBackground(String... args) {


            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("id", Ident.getDNI()));
            params.add(new BasicNameValuePair("nombre", Nombres.getNombre()));
            params.add(new BasicNameValuePair("tablet", Nombres.Tablet()));
            params.add(new BasicNameValuePair("fecha", Titulacion.fecha()));
            params.add(new BasicNameValuePair("test", nombre));
            params.add(new BasicNameValuePair("correctas", correctasString));
            params.add(new BasicNameValuePair("errores", fallosString));
            params.add(new BasicNameValuePair("PC", PC));



            JSONObject json = jsonParser.makeHttpRequest(url_crear_resultados,
                    "POST", params);
            Log.d("Create Response", json.toString());


            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {


                } else {

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }



        protected void onPostExecute(String file_url) {
            pDialog.dismiss();
        }
    }

Is there anything "bad" done? Thanks for the help

laalto

This exception usually comes from dialogs that are still active when the activity is finishing.

In onPreExecute() you create a new dialog but it might be so that pDialog already holds a reference to an active dialog. Some ways around it:

  • Check for pDialog == null before creating a new one. Assign a null to pDialog after dismissing it.

  • If pDialog != null, dismiss() it first before creating a new dialog.

(Also super.onCreateDialog() is unnecessary as you're not doing anything with the returned Dialog.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android leaked window

From Dev

Activity has leaked window - Android

From Dev

Android Activity has leaked window

From Dev

Android : Window Manager : android view window leaked

From Dev

When does Android consider a window is leaked?

From Dev

Activity has leaked window android that was originally

From Dev

When does Android consider a window is leaked?

From Dev

Android MediaPlayer with MediaController: LogCat error "Activity has leaked window that was originally added here"

From Dev

Android window WindowLeaked - Activity has leaked window that was originally added here

From Dev

Leaked windows error with progress dialog android

From Dev

Leaked window error with Progress Dialog even after calling dismiss

From Dev

Android 9.0 Activity has leaked window that was originally added

From Dev

Leaked window in class file

From Dev

Android AsyncTask error in declaration

From Dev

Error in Android application AsyncTask

From Dev

Android AsyncTask error in declaration

From Dev

Android: AsyncTask RecyclerView error;

From Dev

Android: BoundService and leaked ServiceConnection

From Dev

Android: BoundService and leaked ServiceConnection

From Dev

android: Facebook SDK AsyncTask error

From Dev

android asynctask mail send error

From Dev

android: Facebook SDK AsyncTask error

From Dev

error type mismatch asynctask in android

From Dev

Android AsyncTask Error implement abstract

From Dev

Android AsyncTask error when execute

From Dev

'Leaked window error' warning on a device orientation change while Options Menu is open (API 23,24,25)

From Dev

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0

From Dev

Activity com.ui.MapViewer has leaked window android.widget.PopupWindow that was originally added here

From Dev

Activity has leaked window at alertDialog show() method

Related Related

  1. 1

    Android leaked window

  2. 2

    Activity has leaked window - Android

  3. 3

    Android Activity has leaked window

  4. 4

    Android : Window Manager : android view window leaked

  5. 5

    When does Android consider a window is leaked?

  6. 6

    Activity has leaked window android that was originally

  7. 7

    When does Android consider a window is leaked?

  8. 8

    Android MediaPlayer with MediaController: LogCat error "Activity has leaked window that was originally added here"

  9. 9

    Android window WindowLeaked - Activity has leaked window that was originally added here

  10. 10

    Leaked windows error with progress dialog android

  11. 11

    Leaked window error with Progress Dialog even after calling dismiss

  12. 12

    Android 9.0 Activity has leaked window that was originally added

  13. 13

    Leaked window in class file

  14. 14

    Android AsyncTask error in declaration

  15. 15

    Error in Android application AsyncTask

  16. 16

    Android AsyncTask error in declaration

  17. 17

    Android: AsyncTask RecyclerView error;

  18. 18

    Android: BoundService and leaked ServiceConnection

  19. 19

    Android: BoundService and leaked ServiceConnection

  20. 20

    android: Facebook SDK AsyncTask error

  21. 21

    android asynctask mail send error

  22. 22

    android: Facebook SDK AsyncTask error

  23. 23

    error type mismatch asynctask in android

  24. 24

    Android AsyncTask Error implement abstract

  25. 25

    Android AsyncTask error when execute

  26. 26

    'Leaked window error' warning on a device orientation change while Options Menu is open (API 23,24,25)

  27. 27

    Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0

  28. 28

    Activity com.ui.MapViewer has leaked window android.widget.PopupWindow that was originally added here

  29. 29

    Activity has leaked window at alertDialog show() method

HotTag

Archive