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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:28:14+00:00 2026-05-31T08:28:14+00:00

I am trying to schedule a task to update a TextView once a second.

  • 0

I am trying to schedule a task to update a TextView once a second. As long as I have the line, with the comment after it, commented out, everything works fine. Logcat shows someting like:

Task
IN
OUT
Task
IN
OUT
...

But if I uncomment the statusLabel.setText(), this is what I see:

Task
IN
OUT
TASK
IN 

Those five rows are all I get. For some reason it seems to stop, when it tries to set the text again the second time.

My Code:

public class MyActivity extends Activity {

    TextView statusLabel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.control);
        statusLabel = (TextView) findViewById(R.id.statusLabel);

        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(
                new Runnable() {
                    public void run() {
                        Log.d("Datalogger","Task");
                        updateStatus();
                    }
                }, 0, 1, TimeUnit.SECONDS);
    }

    private void updateStatus() {
        Log.d("Datalogger","IN");
        statusLabel.setText("X");  // !! If I comment out this line, 
        Log.d("Datalogger","OUT"); //    everything works
    }
}
  • 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-31T08:28:16+00:00Added an answer on May 31, 2026 at 8:28 am

    The problem is that you are attempting to update UI from a thread other than the UI(main) thread. In the runnable use runOnUiThread(Runnable action) with a new runnable to call updateStatus().

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

Sidebar

Related Questions

I am trying to set a scheduled task in java for running once in
Assume I have 4 tables: Table 1: Task ID Task Schedule 1 Cut Grass
I need some help. I am trying to figure out how to schedule jobs
I am trying to use the ColdFusion administrator to schedule a task. It is
I'm trying to schedule a repeating event to run every minute in Python 3.
I'm trying to use a timer to schedule a recurring event in an application.
I am trying to (simply) make a blocking thread queue, where when a task
I have the task of maintaining an application that started life as a VB6
I am trying to use the parallel task library to kick off a number
Am quite running out of ideas, Here is what am trying to do ,

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.