Skip to content Skip to sidebar Skip to footer

Android Leaked Window

I am using AsyncTask to gather data, and then start a new activity, but I am getting a leaked window. class GetDataTask extends AsyncTask { @O

Solution 1:

See below code

privateclassProgressTaskextendsAsyncTask<String, Void, Boolean> {

privateProgressDialog dialog = newProgressDialog(HomeActivity.this);

protectedvoidonPreExecute() {
    this.dialog.setMessage("Please wait");
    this.dialog.show();
}

protectedBooleandoInBackground(final String... args) {
    try {
        Utilities.arrayRSS = objRSSFeed
                .FetchRSSFeeds(Constants.Feed_URL);
        returntrue;
    } catch (Exception e) {
        Log.e("tag", "error", e);
        returnfalse;
    }
}

@OverrideprotectedvoidonPostExecute(final Boolean success) {

    if (dialog.isShowing()) {
        dialog.dismiss();
    }
        // display UIUpdateDisplay();
}
}

Solution 2:

This is happening because your activity get's destroyed and ProgressDialog leaks. You can duplicate this by pressing power button when progress shows or turning screen 90 degree.

What you need to do with progress dialogs is dismissing them onPause and restoring onResume In my practice it can get pretty complex to track this kind of stuff. When I start AsyncTask from Activity I hook AsyncTask to Application and unhook on completion. Application object stores info about what Activity have what task running and can resume progress dialog when you click Home and return to application.

Post a Comment for "Android Leaked Window"