Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:20:19+00:00 2026-06-14T12:20:19+00:00

I have a problem with an Asynctask, I can’t get the return values of

  • 0

I have a problem with an Asynctask, I can’t get the return values of the doInBackground method in the OnPostExecute, can you help me?

I setted the return value of the Asynctask as an Integer, and the value that I’m returning is an int, so why does the app stop on the return of the doInBackground?

If you can explain to me how the Asynctask works I will really appreciate it.

Thank you very much!!

public class LoginActivity extends Activity 
{
ProgressDialog pDialog;
JSONParser jParser = new JSONParser();

Button btnLogin;
Button btnLinkToRegister;
EditText inputEmail;
EditText inputPassword;
TextView loginErrorMsg;

JSONArray user = null;
ArrayList<HashMap<String, String>> userList;


private static String loginURL = "htttp://example.com/query.php";

private static String KEY_SUCCESS = "success";
private static String KEY_EMAIL = "email";
private static String KEY_PASSWORD = "password";

@Override
public void onCreate(Bundle savedInstanceState) 
{    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    userList = new ArrayList<HashMap<String, String>>();

    inputEmail = (EditText) findViewById(R.id.loginEmail);
    inputPassword = (EditText) findViewById(R.id.loginPassword);
    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);

    btnLogin.setOnClickListener(new View.OnClickListener() 
    {   
        @Override
        public void onClick(View v) 
        {
            new CheckUser().execute();          
        }
    });


}

/**
 * Background Async Task to Load all product by making HTTP Request
 * */

class CheckUser extends AsyncTask<String, String, Integer> 
{
    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() 
    {
        super.onPreExecute();
        pDialog = new ProgressDialog(LoginActivity.this);
        pDialog.setMessage("Verifica dati inseriti...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    protected Integer doInBackground(String... args)
    {
        int valoreOnPostExecute = 0;

        String emailInserted = inputEmail.getText().toString();
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("email", emailInserted));
        // getting JSON string from URL
        JSONObject json = null;

        json = jParser.getJSONFromUrl(loginURL, params);

        // Check your log cat for JSON response
        Log.d("All Users: ", json.toString());

        try 
        {
            // Checking for SUCCESS TAG
            int success = json.getInt(KEY_SUCCESS);

            if (success == 1) 
            {
                // users found
                // Getting Array of users
                user = json.getJSONArray("utenti");

                // looping through All users
                for (int i = 0; i < user.length(); i++) 
                {
                    JSONObject c = user.getJSONObject(i);

                    // Storing each json item in variable
                    String email = c.getString(KEY_EMAIL);
                    String password = c.getString(KEY_PASSWORD);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(KEY_EMAIL, email);
                    map.put(KEY_PASSWORD, password);

                    // adding HashList to ArrayList
                    userList.add(map);
                }

//                    Intent intent = new Intent(LoginActivity.this,GenereMusicale.class);
//                    startActivity(intent);
                    valoreOnPostExecute = success;
                } 
//                else 
//                {
//                  Log.d("success != 1", json.toString());
//                  //Toast.makeText(LoginActivity.this, "Username/password non corretti", Toast.LENGTH_SHORT).show();
//                }
        }
        catch (JSONException e) 
        {
            e.printStackTrace();
            Log.d("User ARRAY", "user array: "+user);
        }

        return valoreOnPostExecute;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(int valoreOnPostExecute) 
    {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        // updating UI from Background Thread

        if(valoreOnPostExecute == 1)
        {
            Intent intent = new Intent(LoginActivity.this,GenereMusicale.class);
            startActivity(intent);
        }
        else
        {
            new AlertDialog.Builder(LoginActivity.this)
            .setTitle("Fine del Round!")
            //.setMessage("Terminare round?")
            //.setNegativeButton(android.R.string.no, null)
            .setPositiveButton(android.R.string.ok, new OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    finish();
                }
            }).create().show();
        }
    }

}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:20:21+00:00Added an answer on June 14, 2026 at 12:20 pm

    Your return type from doInBackground() and receiving type in onPostExecute() does not match

    try like this

    class CheckUser extends AsyncTask<String, String, Integer> 
    
    protected Integer doInBackground(String... args)
    
    protected void onPostExecute(Integer valoreOnPostExecute) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with Android AsyncTask. There is an Activity which contains some
I'll keep this one as simple as I can. I have a method in
Hello everyone I have this problem, I had to make a AsyncTask because the
In my app i have a processDialog (using AsyncTask) and at doInbackground it fetches
I have a problem that I can't solve... In my Activity, I instantiate a
I have this strange problem about loading images using AsyncTask in ListView.In my ListView,
I have an AsyncTask which launches a DatabaseHelper class from DoinBackground which copies an
this problem has been doing my head in and I hope you can help!
I have an Activity which starts an AsyncTask. This AsyncTask uses AutoCompleteTextView.showDropDown() in onPostExecute.
Can I load admob ad using AsyncTask ? I have tried it but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.