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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:33:51+00:00 2026-05-26T02:33:51+00:00

How do i change the background of a LinearLayout via setBackgroundColor() by another thread?

  • 0

How do i change the background of a LinearLayout via setBackgroundColor() by another thread?

I learned, that the Android UI Framework is not threadsafe, so you can’t change UI elements by another Thread than the UI thread.

My goal is to create a strobe light effect by calling the setBackgroundColor() method with changing colors (in this case black/white/black/ect,) on a LinearLayout which fills the entire screen.

  • 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-26T02:33:51+00:00Added an answer on May 26, 2026 at 2:33 am

    One way is to use Handler with message queues. You instantiate the Handler in the main UI thread, then use obtainMessage() to send messages to the Handler. So an example would be like

    public final Handler updateTextView = new Handler(){
       @Override
       public void handleMessage(Message msg)
       {
          if(msg.what == UPDATE_TEXT){
              myTextView.setText("arg1 = " + msg.arg1 +
                                 "; arg2 = " + msg.arg2 + "; " + (String)msg.obj);
          }
       }
    }
    

    Then in your thread you can call:

    String myString = new String("test");
    updateTextView.obtainMessage(UPDATE_TEXT, 10, 20, myString).sendToTarget();
    

    The result if called once will be myTextView now says “arg1 = 10; arg2 = 20; test”.

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

Sidebar

Related Questions

I have a LinearLayout that I would like to change the background color of
I need change background of all text that have two spaces from the start
How can I change the BACKGROUND color of the MDI FORM in C#? I
How to achieve an android:background change effect on multiple Views at the same time,
I am working on an Android application. I want to change the background of
I have a ListView with some elements and I want to change the background
I have a drawable that i use as a Background for a LinearLayout. I
How to dynamically change the background LinearLayout?
i did't find any property of a tab container to change background color of
I have created a table in my application, I want to select (change background

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.