5

While opening java file I first look blank white screen, and after that it appears me splash screen layout. I have java file as:

new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Task 
                    finish();
                }
              }, ARG_SPLASH_TIME);

And in xml file I simply put ImageView and set android:src value. In manifest file I open Splash activity in Launcher Mode.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Krunal Kapadiya
  • 2,853
  • 3
  • 16
  • 37

6 Answers6

13

Finally got my answer Splash Screen in Right Way. I do just following.

In values->styles.xml I created splash screen background image

<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

For below api 19, in values-19->styles.xml I used

<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

I removed setContentview() from SplashActivity and added style for splash screen in Manifest.xml file android:theme="@style/AppTheme.Splash"

Krunal Kapadiya
  • 2,853
  • 3
  • 16
  • 37
4

Use :

<item name="android:windowDisablePreview">true</item>

in your style.xml file for your app theme.

Piyush
  • 18,895
  • 5
  • 32
  • 63
4

Well the white screen is a way for android to make system feel more responsive to user. User taps app and instantly is seeing a result (app).

So how we can change this behawior?

We can disable this preview, as @Piyush wrote:

<item name="android:windowDisablePreview">true</item>

Hovewer this will make your app feel slugish instead, i mean, u will not see anything for a while and then u will see your activity, not really an result u would expect to happen.

Better option is to use in your styles for activity.

<item name="android:windowBackground">@drawable/bg</item>

This will change default background for your application, u can put preloader image for an app, for example with your logo.

User in both situation must wait, but this feels much more responsive

Inverce
  • 1,487
  • 13
  • 27
3

This is a strange issue with newly released Android Studio. First time of launching application take longer than usual(looks white). This issue happens only in debug mode and not effect to your released APK. Also I was suffering this issue and found this solution.

Settings/Preferences→ Build, Execution, Deployment → Instant Run and uncheck Instant Run

Instant run in Android Studio 2.0 (how to turn off)

Community
  • 1
  • 1
Shanto George
  • 994
  • 13
  • 26
3

You can use this style in your splash activity-

<style name="YourTheme">
  <item name="android:windowBackground">@null</item>
</style>
Jainendra
  • 24,713
  • 30
  • 122
  • 169
1

Some answer not work right now so I update this and make sure it's wotk fine. The first create your xml splash file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/black" />

    <item
        android:width="@dimen/_145sdp"
        android:height="@dimen/_30sdp"
        android:drawable="@drawable/your_logo_here"
        android:gravity="center" />
</layer-list>

In your Manifest:

<activity
            android:name=".ui.SplashActivity"
            android:theme="@style/Theme.Splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

and last in your style:

<style name="Theme.Splash" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
<!--        <item name="android:windowNoTitle">true</item>-->
<!--        <item name="android:windowActionBar">false</item>-->
<!--        <item name="android:windowFullscreen">true</item>-->
<!--        <item name="android:windowContentOverlay">@null</item>-->
    </style>

You don't need layout file, it't not necessary, remove setContentView in your class, like this:

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setUpView()
    }


    private fun setUpView() {
        Handler(Looper.getMainLooper()).postDelayed({
            val intent = Intent(this, MainActivity::class.java)
            //startActivity(intent)
            // finishAffinity()
        }, 2000)

    }
}
Hoàng Vũ Anh
  • 647
  • 1
  • 8
  • 24