1. Are you ready for the Galaxy S20? Here is everything we know so far!

AsyncThread cancelled even is success background opration onPostExecute not called

Discussion in 'Android Development' started by Juraj Puchký, Sep 26, 2019.

  1. Juraj Puchký

    Juraj Puchký Lurker
    Thread Starter

    Hi,

    i have problem with my application, i have following AsyncTask and even is
    executed it goes to onCancelled instead of onPostExecute.
    Code (Java):
    1.     private class UserRegisterTask extends AsyncTask<Boolean, Boolean, Boolean> {
    2.  
    3.         private final String mEmail;
    4.         private final String mPassword;
    5.         private final String mFirstName;
    6.         private final String mLastName;
    7.         private final String mAddress1;
    8.         private final String mAddress2;
    9.         private final String mCity;
    10.         private final String mZip;
    11.         private final String mState;
    12.         private final ProgressDialog dialog;
    13.         private final boolean mNewsletter;
    14.  
    15.         private boolean registered = false;
    16.  
    17.         public UserRegisterTask(Activity activity, String email, String password, String firstname, String lastname, String address1, String address2, String city, String zip, String state, boolean newsletter) {
    18.             mEmail = email;
    19.             mPassword = password;
    20.             mFirstName = firstname;
    21.             mLastName = lastname;
    22.             mAddress1 = address1;
    23.             mAddress2 = address2;
    24.             mCity = city;
    25.             mZip = zip;
    26.             mState = state;
    27.             mNewsletter = newsletter;
    28.             dialog = new ProgressDialog(activity);
    29.         }
    30.  
    31.  
    32.         @Override
    33.         protected void onPreExecute() {
    34.             super.onPreExecute();
    35.             registering = true;
    36.             dialog.setMessage("Registruji a přihlašuji, prosím čekejte...");
    37.             dialog.setCanceledOnTouchOutside(false);
    38.             dialog.show();
    39.         }
    40.  
    41.         @Override
    42.         protected void onCancelled() {
    43.             super.onCancelled();
    44.             dialog.dismiss();
    45.             registering = false;
    46.             Toast.makeText(getBaseContext(), R.string.registration_cancelled, Toast.LENGTH_SHORT).show();
    47.         }
    48.  
    49.         @Override
    50.         protected Boolean doInBackground(Boolean... booleans) {
    51.             registered = authService.register(mFirstName, mLastName, mEmail, mPassword, mCity, mAddress1, mAddress2, mZip, mState, mNewsletter);
    52.             return Boolean.TRUE;
    53.         }
    54.  
    55.         @Override
    56.         protected void onPostExecute(Boolean success) {
    57.             super.onPostExecute(success);
    58.             dialog.dismiss();
    59.  
    60.             if (success && registered) {
    61.                 Toast.makeText(getBaseContext(), R.string.registration_success, Toast.LENGTH_LONG).show();
    62.                 redirectToHomepage();
    63.             } else {
    64.                 email.setError(getString(R.string.email_is_already_registered));
    65.                 email.requestFocus();
    66.             }
    67.         }
    68.     }
    69.  
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Juraj Puchký

    Juraj Puchký Lurker
    Thread Starter

    I found solution error was in the wrong URL of API service it causes that returns HTML 404 instead of JSON


     
Loading...

Share This Page

Loading...