• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

AsyncThread cancelled even is success background opration onPostExecute not called

Hi,

i have problem with my application, i have following AsyncTask and even is
executed it goes to onCancelled instead of onPostExecute.
Java:
    private class UserRegisterTask extends AsyncTask<Boolean, Boolean, Boolean> {

        private final String mEmail;
        private final String mPassword;
        private final String mFirstName;
        private final String mLastName;
        private final String mAddress1;
        private final String mAddress2;
        private final String mCity;
        private final String mZip;
        private final String mState;
        private final ProgressDialog dialog;
        private final boolean mNewsletter;

        private boolean registered = false;

        public UserRegisterTask(Activity activity, String email, String password, String firstname, String lastname, String address1, String address2, String city, String zip, String state, boolean newsletter) {
            mEmail = email;
            mPassword = password;
            mFirstName = firstname;
            mLastName = lastname;
            mAddress1 = address1;
            mAddress2 = address2;
            mCity = city;
            mZip = zip;
            mState = state;
            mNewsletter = newsletter;
            dialog = new ProgressDialog(activity);
        }


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            registering = true;
            dialog.setMessage("Registruji a přihlašuji, prosím čekejte...");
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            dialog.dismiss();
            registering = false;
            Toast.makeText(getBaseContext(), R.string.registration_cancelled, Toast.LENGTH_SHORT).show();
        }

        @Override
        protected Boolean doInBackground(Boolean... booleans) {
            registered = authService.register(mFirstName, mLastName, mEmail, mPassword, mCity, mAddress1, mAddress2, mZip, mState, mNewsletter);
            return Boolean.TRUE;
        }

        @Override
        protected void onPostExecute(Boolean success) {
            super.onPostExecute(success);
            dialog.dismiss();

            if (success && registered) {
                Toast.makeText(getBaseContext(), R.string.registration_success, Toast.LENGTH_LONG).show();
                redirectToHomepage();
            } else {
                email.setError(getString(R.string.email_is_already_registered));
                email.requestFocus();
            }
        }
    }
 
I found solution error was in the wrong URL of API service it causes that returns HTML 404 instead of JSON


Hi,

i have problem with my application, i have following AsyncTask and even is
executed it goes to onCancelled instead of onPostExecute.
Java:
    private class UserRegisterTask extends AsyncTask<Boolean, Boolean, Boolean> {

        private final String mEmail;
        private final String mPassword;
        private final String mFirstName;
        private final String mLastName;
        private final String mAddress1;
        private final String mAddress2;
        private final String mCity;
        private final String mZip;
        private final String mState;
        private final ProgressDialog dialog;
        private final boolean mNewsletter;

        private boolean registered = false;

        public UserRegisterTask(Activity activity, String email, String password, String firstname, String lastname, String address1, String address2, String city, String zip, String state, boolean newsletter) {
            mEmail = email;
            mPassword = password;
            mFirstName = firstname;
            mLastName = lastname;
            mAddress1 = address1;
            mAddress2 = address2;
            mCity = city;
            mZip = zip;
            mState = state;
            mNewsletter = newsletter;
            dialog = new ProgressDialog(activity);
        }


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            registering = true;
            dialog.setMessage("Registruji a přihlašuji, prosím čekejte...");
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            dialog.dismiss();
            registering = false;
            Toast.makeText(getBaseContext(), R.string.registration_cancelled, Toast.LENGTH_SHORT).show();
        }

        @Override
        protected Boolean doInBackground(Boolean... booleans) {
            registered = authService.register(mFirstName, mLastName, mEmail, mPassword, mCity, mAddress1, mAddress2, mZip, mState, mNewsletter);
            return Boolean.TRUE;
        }

        @Override
        protected void onPostExecute(Boolean success) {
            super.onPostExecute(success);
            dialog.dismiss();

            if (success && registered) {
                Toast.makeText(getBaseContext(), R.string.registration_success, Toast.LENGTH_LONG).show();
                redirectToHomepage();
            } else {
                email.setError(getString(R.string.email_is_already_registered));
                email.requestFocus();
            }
        }
    }
 
Back
Top Bottom