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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:59:58+00:00 2026-06-14T19:59:58+00:00

I want to access activity and set text from async class. public class MainActivity

  • 0

I want to access activity and set text from async class.

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button getBtn = (Button) findViewById(R.id.btn_result);

        getBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                           TextView txt_res = (TextView)findViewById(R.id.txt_Result);
                           new GetText(txt_res).execute(); // Async class
                }
        });
    }
}

//Async Class

public class GetText AsyncTask<Void, Void, Void>{
    private TextView txt_res;

    public GetText (TextView txt_res) {
        this.txt_res = txt_res;
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
                     String Result = GetTextFromDb();
        } catch (Exception e) {

        }
        return null;
    }

     @Override
 protected void onPostExecute(Void result)
    {
        try
        {
            Log.v("Success", "Success"); // I see "Success" at Logcat
            txt_res.SetText("Success"); // Textview didn't change
        }catch (Exception e) {
            Log.v("Error", e.getMessage()); // No error at Logcat

        }
    }
}

I redefine my question. Textview don’t change. Whats my mistake.

I redefine my question again. Textview didn’t change at two functions(doInBackground, onPostExecute)

  • 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-14T19:59:59+00:00Added an answer on June 14, 2026 at 7:59 pm

    You basically have 2 options. You cannot directly access the main thread from asych obviously, so you must use the proper format.

    1. If the text view needs to be updated after the task finishes, simply do the updating in onPostExecute

    2. If the textview is displaying some intermediate progress, use onProgressUpdate

    Edit:

    Ok so here is your problem now. With asycn tasks, you must return a value from doInBackground. Change the type to String, and change onPostExecute(String result). Void means you are returning nothing. You will also have to change the second of the three parameters at the top of the async task to string as well.

    Also, the method is textview.setText(“”); not textview.SetText(“”). The latter should not compile

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access a static variable from a static method: #!/usr/bin/env python class
i want to access a integer and a string from a class to all
Main class has two variables that want to access another class: public class MyClassA
I want to access the Window class so I can set the screen brightness
I have ArrayList>. In another activity I want to access all values stored in
I want to access text-shadow property just like we access padding property. Means ,
I have a RESTful web service and I want to access it from Android.
I am using twitter4j and the following code: public static void OAuthLogin(Activity a) {
I want to access the values of latitude and longitude of one class in
I have some shared preferences (latitude, longitude) that I want to access from a

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.