I want to display a logo for few seconds before application starts and menu is visible. I want also to use some when it disappears. Should I create a new activity? Can I set it in layout ?
-
this may help you: http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/ – Jun 27 '11 at 15:31
-
Like a splash screen? [Here](http://www.droidnova.com/how-to-create-a-splash-screen,561.html) is an example. – Stefan Bossbaly Jun 27 '11 at 15:31
7 Answers
define a layout for the splash screen which will contain your logo , and then , add this code to your activity :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
//display the logo during 5 seconds,
new CountDownTimer(5000,1000){
@Override
public void onTick(long millisUntilFinished){}
@Override
public void onFinish(){
//set the new Content of your activity
YourActivity.this.setContentView(R.layout.main);
}
}.start();
}
-
This is not pretty good, because the app can be runned faster than 5 sec – Konstantin Konopko Sep 04 '18 at 18:28
-
@KonstantinKonopko it depends on what you're loading on app start. you can use a SplashScreen with the logo and run an AsyncTask on the background for app starting or loading, so if the app run fast, the logo will be displayed until the onPostExecute is called. – Houcine Sep 05 '18 at 22:01
You can use splash logo at startup using styles-only method. Unfortunately it works only starting form API 23. But you don't need manage splash Activity.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:windowBackground">@drawable/logo_startup</item>
<item name="android:windowNoTitle">true</item>
</style>
res/drawable-v23/logo_startup.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/PageBackground"/>
<item android:width="@dimen/logo_startup" android:height="@dimen/logo_startup" android:gravity="center">
<bitmap android:src="@drawable/logo"/> //use PNG file here, not vector
</item>
</layer-list>
res/drawable/logo_startup.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/PageBackground"/>
</layer-list>

- 5,229
- 4
- 36
- 62
You can use an image view that gets setVisibility(Visibility.GONE); or something to that extent, or you can write an activity that just pops up and drops out after a time ends. That is your personal preference...

- 1,557
- 1
- 13
- 27
Why? Users don't like to wait. However, if you need to wait because you're loading some data, you can:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
/* Do some work in a new thread, calling setContentView at the end with your view */
}

- 98,571
- 55
- 246
- 278
Here are a few intros to making a splash-page:
http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/
http://blogingtutorials.blogspot.com/2010/11/splash-graphics-activity-in-android.html
Activity file:
package com.karan.android.video;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class splash extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread splashThread = new Thread()
{
@Override
public void run()
{
try {
int waited = 0;
while (waited < 3000)
{
sleep(100);
waited += 100;
}
} catch (InterruptedException e)
{
// do nothing
} finally
{
finish();
Intent i = new Intent(splash.this,video.class);
startActivity(i);
}
}
};
splashThread.start();
}
}
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/buff"
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:textSize="40dp"
android:textColor="#CCFF00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Buffering..."
/>
</FrameLayout>

- 481
- 5
- 13

- 79
- 2
Delayed execution can be implemented in simplier way:
new Handler().postDelayed(new Runnable() {
// ... Hide splash image and show the real UI
}, 3000)
Also the android standard android.widget.ViewSwitcher
class is very usable for this kind of things.

- 5,154
- 2
- 20
- 18