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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:03:04+00:00 2026-05-20T10:03:04+00:00

I am making an application in which i am changing the the layout background

  • 0

I am making an application in which i am changing the the layout background continually like flipping the background, I am implementing the background change using Activity.runOnUiThread() function since it is a UI function and waiting for 2 seconds using Thread().sleep() but the application only shows the layout color I mentioned in the end.

package com.tutorial.flasher;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
//import android.os.SystemClock;
//import android.os.SystemClock;
import android.widget.LinearLayout;


public class flasher extends Activity {
    /** Called when the activity is first created. */
     LinearLayout llaLayout;
     Thread th = new Thread("ThreadOne");
     Activity _activity = new Activity();


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    llaLayout = (LinearLayout)findViewById(R.id.layo);



    Thread t1 = new Thread(new Runnable() {

        public void run() {
            try
            {
                Thread.sleep(2000);
            }
            catch (Exception e) {
                // TODO: handle exception
            }
        }
    });

    t1.start();
    t1.run();
    t1.stop();


     _activity.runOnUiThread(new Runnable(){
        public void run(){
            llaLayout.setBackgroundColor(Color.parseColor("#00FF00"));

        }
    });
    //t1.currentThread();
    t1.start();
  t1.run();
    t1.stop();

    _activity.runOnUiThread(new Runnable(){
        public void run(){
                                //Color BLUE of layout
            llaLayout.setBackgroundColor(Color.parseColor("#0000FF"));

        }
    });


}

}

Both the UI changes and Thread staring would be happening in a loop(which is not shown) but still the application is changing the layout color only once.
Thanks,
Sid

  • 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-20T10:03:05+00:00Added an answer on May 20, 2026 at 10:03 am
    1. You should not new Activity, Activity is created by Android system.
    2. Call Thread.start will start the thread, there is no need to call Thread.run.

    Activity.runOnUiThread maybe not the best way to archive this, try Handler. Here is sample code:

    public class BroadcastActivity extends Activity {
    
        public static final int CHANGE_BGCOLOR = 1;
    
        private LinearLayout llaLayout;
    
        private Handler handler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                if (msg.what == 1) {
                    String color = (String) msg.obj;
                    llaLayout.setBackgroundColor(Color.parseColor(color));
                    String nextColor = ""; // Next background color;
                    Message m = obtainMessage(CHANGE_BGCOLOR, nextColor);
                    sendMessageDelayed(m, 200);
                }
            }
        };
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            llaLayout = (LinearLayout)findViewById(R.id.layo);
            String nextColor = ""; // Next background color;
            Message m = handler.obtainMessage(CHANGE_BGCOLOR, nextColor);
            handler.sendMessageDelayed(m, 200);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im making an application which uses few languages. I would like to have possibility
I'm making a php web application which stores user specific information that is not
I am making an application in C# which uses a winform as the GUI
I am planning on making a change to the data layer of my application
I am making an application with Java Swing and i have a problem. I
I am making an application that does some custom image processing. The program will
Where is a good place to start with making an application in .NET that
I'm making a Java application with an application-logic-thread and a database-access-thread. Both of them
I'm making a web application and I got the design for it from a
I'm making a WPF application that is comprised of Screens (Presenter + View). I

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.