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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:12:48+00:00 2026-06-17T06:12:48+00:00

I start a thread in activity . There is a constructor textview in thread

  • 0

I start a thread in activity. There is a constructor textview in thread. It has no error of setText when update the textview in run.

But if I new a thread without parameter, then setTextView (TextView) and setText() in run.. There is the error.

Why it can appear this?

Edit: My code

package extthread;

import android.widget.TextView;

public class MyUpdateUIThread extends Thread {

private TextView textView1;

public MyUpdateUIThread(TextView textView1) {
super();
this.textView1 = textView1;
}

@Override
public void run() {
super.run();
textView1.setText("zzzzzzzzzzzzzz");
}

}

------------------------------
package testtest.test.run;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import extthread.MyUpdateUIThread;

public class Main extends Activity {
TextView textView;

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

textView = (TextView) this.findViewById(R.id.textView1);
Thread thread = new Thread(new MyUpdateUIThread(textView));
thread.start();

}
};
  • 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-17T06:12:49+00:00Added an answer on June 17, 2026 at 6:12 am

    Use runOnUiThread inside run method of Thread for updating TextView as:

    Your_Current_Activity.this.runOnUiThread(new Runnable() {
        public void run() {
    
                 //update textview here
        }
    });
    

    EDIT :

    as in your current code Thread is from separate class . then you will need to pass Main Activity instance to Thread class to access runOnUiThread in MyUpdateUIThread thread . change your MyUpdateUIThread class constructor as:

    private TextView textView1;
    Activity activity;
    public MyUpdateUIThread(TextView textView1,Activity activity) {
    super();
    this.textView1 = textView1;
    this.activity=activity;
    }
    
    @Override
    public void run() {
    super.run();
    activity.runOnUiThread(new Runnable() {
        public void run() {
    
           //update textview here
           textView1.setText("zzzzzzzzzzzzzz");
        }
    });
    
    }
    

    and create MyUpdateUIThread object in Main Activity as:

    Thread thread = new Thread(new MyUpdateUIThread(textView,Main.this));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My activity works fine using thread but when there is 10 or more images
Android tells me that The application has stopped unexcepetedly, but there are no error's
I'm not able to start activity from thread. I want to start one activity
If i use thread like this: void foo() { new Thread().Start(); } since the
I want to get the thread's start address with NtQueryInformationThread , but I need
In my Android app, the main Activity will sometimes start a Thread to load
In My application there is one thread running in activity A while it is
I´ve heared that the main Activity should run in a different thread than the
There is a case that when a user presses the button a new TextView
Code: setContentView(R.layout.splashscreen); Thread timer = new Thread() { @Override public void run() { //

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.