1

I created a splash screen for my application using an empty activity that stays visible for 3 seconds with a background image. Usually, the application starts with a white screen before the background image becomes visible, however, some applications are already started with the "real" splash screen image. How to implement this?

HassanUsman
  • 1,787
  • 1
  • 20
  • 38
Joao
  • 29
  • 1
  • 4

3 Answers3

4

you can use splash screen in this way.

  1. Add style for splash screen activity in styles.xml

    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/yourImageName</item>
    </style>
    
  2. Add that style as theme to your SplashScreenActivity in manifest file

    <activity android:name=".SplashScreenActivity"
        android:theme="@style/SplashTheme"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
  3. Remove setContentView() in SplashScreenActivity's onCreate() Method and use it as a java file which extends AppCompactActivity

Sagar A
  • 89
  • 7
2

The problem is because system process draws initial blank screen when launching the app, from documentation:

A common way to implement a themed launch screen is to use the windowDisablePreview theme attribute to turn off the initial blank screen that the system process draws when launching the app. However, this approach can result in a longer startup time than apps that don’t suppress the preview window. Also, it forces the user to wait with no feedback while the activity launches, making them wonder if the app is functioning properly.

You can disable it with windowDisablePreview attribute, something like this:

  <application
      ...
      android:windowDisablePreview="true">
   ...
  </application>
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
0

Splash Activity usually starts with the background. Try this code, it might help you.

Code for your splash activity page.

public class SplashScreen extends AppCompatActivity {

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

Thread myThread = new Thread(){

    @Override
    public void run() {
        try {
            sleep(3000);
            Intent intent = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intent);
            finish();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
};
    myThread.start();
}}

In layout file, you need to include just Image which you want to see on the splash page.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_splash_screen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">
   <ImageView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:src="@drawable/capture"
       />
</RelativeLayout>

And make sure you add the Splashscreen page before Main activity in Manifest.

 <activity android:name=".SplashScreen">
Arjun
  • 1,294
  • 13
  • 24