Skip to content Skip to sidebar Skip to footer

Android Listview Window Leak Error

I am having a bit of a problem on my hands and I'm going to need a little. My app keeps crashing and when I look at the stacktrace this is what I get back... theproblemsolver.List

Solution 1:

It appears that your AsyncTask has a strong reference to your Activity. Please consider using a static class with a WeakReference instead.

private static class StaticAsyncTask extends AsyncTask<String, String, String>() {
    private WeakReference<Activity> mActivityRef;

    private StaticAsyncTask(Activity callingActivity) {
        mActivityRef = new WeakReference<Activity>(callingActivity);
    }

    @Override
    protected String doInBackground(String... args) {
        // TODO: Do stuff
    }

    @Override
    protected void onProgressUpdate(String... progress) {
        // TODO: Do stuff
    }

    @Override
    protected void onPostExecute(String results) {
        Activity activity = mActivityRef.get();
        if (activity != null) {
            // TODO: Do stuff with my non-null activity
        }
    }
}

Post a Comment for "Android Listview Window Leak Error"