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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:15:58+00:00 2026-06-14T10:15:58+00:00

The following code is for a splash screen in my app.What I need to

  • 0

The following code is for a splash screen in my app.What I need to be done is when the activity loads the image should be displayed as default and then after few seconds the image should be changed to another in the same activity. I have another image like the first one with different color. I wanted to change the screen for that image after few seconds.

I have done it like this in my code.

package com.ruchira.busguru;

import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class SplashScreen extends Activity {

    ImageView imgBus;
    MediaPlayer introSound, bellSound;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        imgBus = (ImageView) findViewById(R.id.imgBus);
        imgBus.setImageResource(R.drawable.blackbus);
        introSound = MediaPlayer.create(SplashScreen.this, R.raw.enginestart);
        introSound.start();

                Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                } catch (InterruptedException e) {              
                    e.printStackTrace();
                }finally{
                   imgBus.setImageResource(R.drawable.bluekbus);    
                }
            }
        };
        timer.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.splash_screen, menu);
        return true;
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        introSound.stop();
        finish();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        introSound.stop();
        finish();
    }
}

but the problem is the program stops by executing in the thread saying…

“android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.”

How I can achieve this target ? Does anybody please help me to sort out this problem. I am new to android development..

Thanks.

  • 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-06-14T10:15:59+00:00Added an answer on June 14, 2026 at 10:15 am

    You should use the ImageView’s Handler and a Runnable. Handler’s are schedulers specific to Android and they can run on the UI thread. Try this:

    ImageView imgBus;
    MediaPlayer introSound, bellSound;
    Runnable swapImage = new Runnable() {
        @Override
        public void run() {
            imgBus.setImageResource(R.drawable.bluekbus);
        }
    };
    

    And inside onCreate() call:

    imgBus = (ImageView) findViewById(R.id.imgBus);
    imgBus.setImageResource(R.drawable.blackbus);
    imgBus.postDelayed(swapImage, 3000);  // Add me!
    

    Understand that splash screens are frowned upon because you should focus on starting the app as soon as possible (while loading the slower element in the background). However sometimes a slight delay is unavoidable.

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

Sidebar

Related Questions

While compiling the following code {\centering {\includegraphics[scale=.5]{splash.eps}} \caption{Splash Screen} \par} \end{figure} Splash screen is
I am using the following code to display splash screen, but it is showing
In my app when the splash screen gets started I am downloading an image
This is my code. When I click on my app logo, after the splash
I have a simple html/javascript based Android app that loads with the following code:
Following code iterates through many data-rows, calcs some score per row and then sorts
I want to create a splash screen that will then move to the login/register
Currently, I am showing splash screen in my desktop application using the following way
I have following code. public class SplashScreen extends Activity { private int _splashTime =
Please following code I am not getting why it's not loading data. below activity

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.