I wanted to do show a splash screen in my application only once for the first time when user downloads my application. How do you design it? What logic will you use for it?

Asked 22-Jan-2018
Updated 22-Jan-2018
Viewed 507 times

1

 I wanted to do show a splash screen in my application only once for the first time when a user downloads my application. How do you design it? What logic will you use for it?


1 Answer


0

to use a splash screen in your android application you need two things - 

  1.  make a xml file which contains the designing part
  2. your logic part in java such as for how long you want to show your screen.


a sample of an XML file 

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/back" />

    <item>

        <bitmap android:src="@drawable/logo"

            android:gravity="center" />

    </item>

</layer-list>


you Splash Activity can contain code

public class SplashActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 1000;

    @Override

    protected void onCreate(Bundle savedInstances){

        super.onCreate(savedInstances);

        new Handler().postDelayed(new Runnable() {

            @Override

            public void run() {

                // This method will be executed once the timer is over

                // Start your app main activity

                Intent i = new Intent(getApplicationContext (), MainActivity.class);

                startActivity(i);

                // close this activity

                finish();

            }

        }, SPLASH_TIME_OUT);

    }

}

you need to make sure that you set your SplashActivty as launcher activity in your app manifest file.