shining
shining

Reputation: 11

Error while calling external AsyncTask from fragment

Can some one please help me with this issue . I am calling an AsyncTask when ever there is SharedPreference change in fragment.

public class UbiSavePreferenceTask extends AsyncTask {

    public final AsyncTask<JSONObject, Integer, Boolean> parallelExecute(JSONObject pref) {
    return parallelExecute(pref);
}

In My fragment

emailNotificationPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference,Object newValue) {
            JSONObject json = new JSONObject();
            try {
                json.put("Email", newValue);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            UbiSavePreferenceTask savePref = new UbiSavePreferenceTask(mContext);
            savePref.parallelExecute(json);

            return true;

        }

});

but parallelExecute method in Async task in going to an infinite loop so i am getting stackOverflowError. Is there any way i can come out of this error . Please let me know.

Upvotes: 0

Views: 166

Answers (1)

KLiFF
KLiFF

Reputation: 382

The method parallelExecute calls itself, so it is normal that it goes in an infinite loop!

public final AsyncTask<JSONObject, Integer, Boolean> parallelExecute(JSONObject pref) {
    return parallelExecute(pref); // <--- here the method calls itself!
}

I hope this helps!

Upvotes: 1

Related Questions