Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image on start up / loading

I ma developing an app, which at the moment when it is loading from the onCreate point, I just have a black screen (until the app gets its footing). Looking at other apps they have a company logo or cool image that pops up for a few seconds, can someone tell me how to do this please?

And if you can set it to display for a minimal time?

like image 484
Paul Avatar asked Jun 19 '11 17:06

Paul


2 Answers

Create a new activity that displays the image for a few seconds and redirects to your main activity:

public class SplashActivity extends Activity
{
    private static final long DELAY = 3000;
    private boolean scheduled = false;
    private Timer splashTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        splashTimer = new Timer();
        splashTimer.schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                SplashActivity.this.finish();
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
         }, DELAY);
       scheduled = true;
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (scheduled)
            splashTimer.cancel();
        splashTimer.purge();
    }
}

Set your image as the background for this activity. Hope that helps. Good luck!

like image 175
Srichand Yella Avatar answered Sep 21 '22 13:09

Srichand Yella


This start up image also known as 'splash screen'. Here you can find how to make splash screen.

like image 44
jamapag Avatar answered Sep 21 '22 13:09

jamapag