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

  • Home
  • SEARCH
  • 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 4098612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:19:29+00:00 2026-05-20T20:19:29+00:00

Okay, this has me confused once again. I am trying to either A: set

  • 0

Okay, this has me confused once again. I am trying to either A: set a golbal variable, which i can do or B: retieve a variable from my AsyncTask. I have set can set the golbal variable from asynctask which is fine, but the activity calls it before it is set with the asynctask.

So therefore I need the application to finsh the AsyncTask before calling the golbal variable.

new createUser().execute();                         
Log.i("res", "After: " + Boolean.toString(MyProperties.getInstance().valut));

private class createUser extends AsyncTask<Void, Void, Boolean> {

    ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "",
            "Creating User...", true);
    Toast toast = Toast.makeText(getApplicationContext(), "",
            Toast.LENGTH_SHORT);

    @Override
    protected Boolean doInBackground(Void... params) {
        // TODO Auto-generated method stub

        if (db.createUser(nameU.getText().toString(), userU.getText()
                .toString(), emailU.getText().toString(), passU.getText()
                .toString()) == false) {
            return false;
        } else {
            return true;
        }
    }

    protected void onPreExecute() {
        dialog.show();
    }

    protected void onPostExecute(Boolean result) {
        dialog.dismiss();
        if (!result) {
            toast.setText("User already exists!");
            toast.show();
            res = result;
            MyProperties.getInstance().valut = res;
            Log.i("res", Boolean.toString(MyProperties.getInstance().valut));

        } else {
            toast.setText("Success");
            toast.show();
            res = result;
            MyProperties.getInstance().valut = res;
            Log.i("res", Boolean.toString(MyProperties.getInstance().valut));
        }
    }
}
  • 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-05-20T20:19:30+00:00Added an answer on May 20, 2026 at 8:19 pm

    Work with your global variable in onPostExecute method of your AsyncTask. You need to implement it in your AsyncTask‘s child. This method is called then all work is done.

    EDIT

    private class createUser extends AsyncTask<Void, Void, Boolean> {
    
        ProgressDialog dialog;
    
        @Override
        protected Boolean doInBackground(Void... params) {
            // TODO Auto-generated method stub
    
            if (db.createUser(nameU.getText().toString(), userU.getText()
                    .toString(), emailU.getText().toString(), passU.getText()
                    .toString()) == false) {
                return false;
            } else {
                return true;
            }
        }
    
        protected void onPreExecute() {
            dialog = ProgressDialog.show(MainActivity.this, "", "Creating User...", true);
            dialog.show();
        }
    
        protected void onPostExecute(Boolean result) {
            dialog.dismiss();
            Toast.makeText(
                getApplicationContext(), 
                result?"Success":"User already exists!", 
                Toast.LENGTH_SHORT).show();
            MyProperties.getInstance().valut = result
            Log.i("res", Boolean.toString(MyProperties.getInstance().valut));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay people, I'm sure someone has had this issue and can help me out.
okay, this has got to be simple - but I can't seem to find
Okay I'm really sorry if this question has been asked, but I can't seem
Okay, so this bug has cost me quite a bit of time and embarrassment.
Okay, I really know this has GOT to be the long way around doing
Okay, this question has evolved a bit, and I want to try to start
Okay, I will cut and paste from .NET reflector to demonstrate what I'm trying
Okay I'm totally confused on this one. I have a script that receives a
Okay guys, I'm sure this has a very simple solution but my searches are
Greetings all, This has confused me ever since I first started coding in C#.

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.