caipivara
8/8/2016 - 6:52 PM

Android - One right way to show a splash screen

Android - One right way to show a splash screen

<resources>
  
  <style name="Splash" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/winwin_colorPrimary</item>
    <item name="colorPrimaryDark">@color/winwin_colorPrimaryDark</item>
    <item name="android:windowBackground">@drawable/splash</item>
  </style>
  
</resources>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item>
    <color android:color="@color/white" />
  </item>

  <item>
    <bitmap
      android:gravity="center"
      android:src="@mipmap/ic_launcher"
      android:tileMode="disabled" />
  </item>

</layer-list>
<manifest>

    <activity
      android:name=".screens.SplashActivity"
      android:configChanges="orientation|keyboardHidden"
      android:screenOrientation="portrait"
      android:taskAffinity=".activity.MainDrawerActivity"
      android:theme="@style/Splash">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    
</manifest>
class SplashActivity : BaseActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    startActivity(Intent(this, MainActivity::class.java))
    finish()
  }
}