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 7650977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:23:26+00:00 2026-05-31T11:23:26+00:00

Update1 activity: public Integer _number = 0; @Override public void onCreate(Bundle savedInstanceState) { if

  • 0

Update1

activity:

public Integer _number = 0;
@Override
    public void onCreate(Bundle savedInstanceState) {
if (_number >0)
        {
            Log.d("onSuccessfulExecute", ""+_number);
        }
        else
        {
            Log.d("onSuccessfulExecute", "nope empty songs lists");
        }
}

public int onSuccessfulExecute(int numberOfSongList) {

_number = numberOfSongList;

if (numberOfSongList >0)
{
    Log.d("onSuccessfulExecute", ""+numberOfSongList);
}
else
{
    Log.d("onSuccessfulExecute", "nope empty songs lists");
}
    return numberOfSongList;
}

end Update1

UPDATE: AsynchTask has its own external class.

How to pass an value from AsyncTask onPostExecute()… to activity

my code does returning value from onPostExecute() and updating on UI but i am looking for a way to set the activity variable (NumberOfSongList) coming from AsynchTask.

AsyncTask class:

@Override
    public void onPostExecute(asynctask.Payload payload)
    {  
         AsyncTemplateActivity app = (AsyncTemplateActivity) payload.data[0];

             //the below code DOES UPDATE the UI textView control
             int answer = ((Integer) payload.result).intValue();
             app.taskStatus.setText("Success: answer = "+answer);

            //PROBLEM:
            //i am trying to populate the value to an variable but does not seems like the way i am            doing:
            app.NumberOfSongList = payload.answer;
            ..............
            ..............
    }

Activity:

  public Integer NumberOfSongList;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 

        //Several UI Code   
        new ConnectingTask().execute();
        Log.d("onCreate", ""+NumberOfSongList);

    } 
  • 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-31T11:23:28+00:00Added an answer on May 31, 2026 at 11:23 am

    What about using a setter method? e.g.

    private int _number;
    public int setNumber(int number) {
        _number = number;
    }
    

    UPDATE:

    Please look at this code. This will do what you’re trying to accomplish.

    Activity class

    public class TestActivity extends Activity {
        public int Number;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.test);
    
            Button btnDisplay = (Button) findViewById(R.id.btnDisplay);
            btnDisplay.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    Toast toast = Toast.makeText(v.getContext(), "Generated number: " + String.valueOf(Number), Toast.LENGTH_LONG);
                    toast.show();               
                }
            });
    
            new TestTask(this).execute();
        }
    }
    

    AsyncTask class

    public class TestTask extends AsyncTask<Void, Void, Integer> {
        private final Context _context;
        private final String TAG = "TestTask";
        private final Random _rnd;
    
        public TestTask(Context context){
            _context = context;
            _rnd = new Random();
        }
    
        @Override
        protected void onPreExecute() {
            //TODO: Do task init.
            super.onPreExecute();
        }
    
        @Override
        protected Integer doInBackground(Void... params) {
            //Simulate a long-running procedure.
            try {
                Thread.sleep(3000);         
            } catch (InterruptedException e) {
                Log.e(TAG, e.getMessage());
            }
    
            return _rnd.nextInt();
        }
    
        @Override
        protected void onPostExecute(Integer result) {
            TestActivity test = (TestActivity) _context;
            test.Number = result;       
            super.onPostExecute(result);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have defined a Activity: public class DialogActivity extends Activity{ @Override public void
Screen2.java file has the following code : public class screen2 extends Activity { public
In a very short and simple LVL callback function, I have: public void applicationError(ApplicationErrorCode
I implement TextWatcher in the Activity : public class Coordinate extends Activity implements TextWatcher
package com.em.progressb; public class progressb extends Activity implements OnClickListener { ProgressDialog dialog; int increment;
i am using a class which extends Handler class to update my activity UI.
Update getting error when i try to call the method from Activity: SQLiteDatabase db
in my activity I originally used a handler to update the UI with data
I am developing an activity which have an Update button as menu for android.
[update2] One of those problems I solved & can't remember how... :) [update1] could

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.