1

In android when you start YouTube you get a view for couple of seconds then start what is after that, like this image attached

Example of Youtube app

another example of reddit app

my approach is create an activity and in onCreate i declare an countdowntimer for seconds just like this code:

new CountDownTimer(2000, 1000) {
        public void onTick(long millisUntilFinished) {
        }
        public void onFinish() {
            startActivity(new Intent(WelcomingActivity.this, LoginActivity.class));
            finish();
        }
    }.start();

is this a good way to do it ? Thanks in advance !

Fahd Al-Qahtani
  • 188
  • 1
  • 9
  • 2
    Check this https://www.bignerdranch.com/blog/splash-screens-the-right-way/ You wont need to setup a timer – jayeshsolanki93 May 12 '17 at 14:16
  • It is called a splashscreen – Denny May 12 '17 at 14:16
  • I'm pretty sure this is just a very lightweight activity to show as a curtain while the rest of the application is starting. Thus, rather than having a countDown, you should listen an event signaling the application is ready. – Jeremy Grand May 12 '17 at 14:17
  • 1
    Possible duplicate of [Android - Prevent white screen at startup](http://stackoverflow.com/questions/37437037/android-prevent-white-screen-at-startup) – Ivan Milisavljevic May 12 '17 at 15:02
  • Its a duplicate question please check questions before posting For example: https://stackoverflow.com/a/31251185/3272539 – Andrew Kochura May 12 '17 at 14:31
  • It's hard to search for something you don't know what the term is – Denny May 13 '17 at 01:41

2 Answers2

-1
  1. Create SplashScreenActivity.java:

    public class SplashScreenActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash_screen);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
                    startActivity(i);
                    finish();
                }
            }, 2000); // your screen will disappear after 2 seconds
        }
    }
    
  2. Register activity in your AndroidManifest.xml:

    <activity android:name="SplashScreenActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
    </activity>
    
  3. And create a layout for your splash screen: activity_splash_screen.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/gradient_background" >
    
        <ImageView
            android:id="@+id/imgLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="your_image" />
    
    </RelativeLayout>
    
Bogdan Kobylynskyi
  • 1,150
  • 1
  • 12
  • 34
-1

the easiest way to it is

make an activity called splash then inside the xml for the activity place your logo you want to use in either an ImageView or as a

android:background  //in your </LinearLayout>

then in the java class of the activities onCreate simply write

 int secondsDelayed = 2;
    new Handler().postDelayed(new Runnable() {
        public void run() {
            startActivity(new Intent(Splash.this, Login.class));
            finish();
        }
    }, secondsDelayed * 1000);
}