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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:48:11+00:00 2026-05-26T07:48:11+00:00

I have written a function to create a splash screen with a 5 second

  • 0

I have written a function to create a splash screen with a 5 second timeout for my app.

The code works fine, but when the timeout reaches zero and I want to redirect to my main activity, the app crashes with the following error:

Only the original thread that created a view hierarchy can touch its views.

So I looked around a bit and someone suggested nesting this inside my function. It seems like a good Idea, but now methods like sleep / stop won’t work.

My code is below, I can provide more / explain more in details if it isn’t clear enough just let me know. Thanks for the help.

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showSplashScreen();

    }

    protected boolean _active = true;
    protected int _splashTime = 5000;  // Splash screen is 5 seconds

    public void showSplashScreen() {

        setContentView(R.layout.splash_layout);

//      Thread splashThread = new Thread() {

         runOnUiThread(new Runnable() {

             @Override
             public void run() {
                 try {
                     int waited = 0;
                     while (_active && (waited < _splashTime)) {
                         Thread.sleep(100);
                         if (_active) {
                             waited += 100;
                         }
                     }
                 } catch (InterruptedException e) {
                     // do nothing
                 } finally {
                     showApplication();
                 }
             }
         });
    }
  • 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-26T07:48:12+00:00Added an answer on May 26, 2026 at 7:48 am

    This will perform sleep on the UI thread. That’s never a good idea.

    Why not something like this?

    new Handler().postDelayed(new Runnable() {
        public void run() {
            // start application ...
        }
    }, _splashTime);
    

    But this answer has a good point. Displaying a splash screen for 5 seconds can be very annoying.

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

Sidebar

Related Questions

I have written a function for a multilevel wordpress menu, but I'd like it
I have written a PHP function to take a video embed code that has
I have written the following function: -- Gets stats for all markets CREATE OR
I have written this innocent javascript code, which lets the user create two markers
I have written this function in SQL and I can't figure out why but
We have a function written in pl/sql(oracle) as below: CREATE OR REPLACE PROCEDURE folder_cycle_check
I have a function written in pl/pgsql which works in the same way as
I have written a function that gets a given number of random records from
I have written a function that positions a tooltip just above a textbox. The
I have written a function below: void trans(double x,double y,double theta,double m,double n) {

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.