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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:36:08+00:00 2026-05-23T09:36:08+00:00

So I am trying to create a strobe light effect in my app. To

  • 0

So I am trying to create a “strobe” light effect in my app.

To do this I need a time delay, one of 100ms the other of 20.

Here is the code I’m using.

Thread timer = new Thread();
    long longTime = 100;
    long shortTime = 20;
    for (int x = 0; x < 2000000; x++)
    {
        layout.setBackgroundColor(background);
        try {
            timer.sleep(longTime);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        layout.setBackgroundColor(backgroundBlack);
        try {
            timer.sleep(shortTime);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

The issue I have is that when I click the button to call that code, nothing happens. So I’ve done a bit of debugging and am pretty sure it is the timing call. I have never programmed in Java before so I am unsure how to call a Thread Sleep.

  • 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-23T09:36:08+00:00Added an answer on May 23, 2026 at 9:36 am

    You could use a Handler as below to achieve this.

    public class Strobe extends Activity {
    
        private LinearLayout mLinearLayout;
    
        private Handler mHander = new Handler();
    
        private boolean mActive = false;
        private boolean mSwap = true;   
    
        private final Runnable mRunnable = new Runnable() {
    
            public void run() {         
                if (mActive) {
                    if (mSwap) {                    
                        mLinearLayout.setBackgroundColor(Color.WHITE);
                        mSwap = false;
                        mHander.postDelayed(mRunnable, 20);
                    } else {
                        mLinearLayout.setBackgroundColor(Color.BLACK);
                        mSwap = true;
                        mHander.postDelayed(mRunnable, 100);
                    }
                }           
            }
        };
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mLinearLayout = (LinearLayout) findViewById(R.id.strobe);
            startStrobe();
        }
    
        private void startStrobe() {        
            mActive = true;
            mHander.post(mRunnable);
        }
    }
    

    Set a Theme to the Activity to make it full screen.

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a basic strobe light in the browser using the canvas
Ok so I am trying create a login script, here I am using PHP5
Trying to create my first iPhone app that would play back audio. When I
I'm trying create a box in my Django app that displays text (and possibly
Trying to create an iPhone app (Objective-C) for my school. I want it to
I'm trying to create a 'glow' effect using the Android Path class. However, the
I'm trying to create a SVG filter that would create an Anaglyph effect. What
I'm trying create this function such that if any key besides any of the
I'm trying create a gantt chart with highcharts and I need to put the
I am trying create the image enlargement effect when you hover your mouse over

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.