Android SharedPreferences Tutorial and Example

Creating a Splash Screen With Animation in Android

A splash screen gives an Android app a clear visual starting point while its first screen is being prepared. A small logo, brand colour, or subtle motion can make the launch feel deliberate instead of making users stare at a blank window.

Modern Android development uses the Android 12 splash screen system rather than a separate activity that exists only to display an image. The AndroidX SplashScreen library also makes the same implementation work across older Android versions, which is useful when an app supports a wide range of devices.

For Australian audiences, a fast startup matters on busy commutes through Sydney, Melbourne, or Brisbane, where users may open an app while changing trains or waiting for a tram. A long animated intro can quickly become frustrating, especially when mobile coverage changes between suburbs and underground stations.

This tutorial uses Kotlin, XML resources, and a short entrance animation. The approach suits a new project or an existing app that uses activities, fragments, SQLite, SharedPreferences, or a ListView-based interface.

Choose A Modern Splash Screen Approach

Android 12 introduced a standardised launch screen that appears automatically when an application starts. It displays a background, an app icon, and the theme used by the first activity. Using this system avoids the common problem of a manually created splash activity adding unnecessary time to startup.

Add the AndroidX dependency to the module-level build.gradle.kts file:

dependencies {
    implementation("androidx.core:core-splashscreen:1.0.1")
}

The library version can change, so check the current stable release in Android Studio or Google’s AndroidX documentation. Sync the project after adding the dependency and make sure the app uses a recent compile SDK.

A splash screen should communicate that the app is loading, not delay access to the main interface. Keep visual movement brief and use the system screen for launch branding. Run longer data preparation in a ViewModel or repository while the first usable screen is displayed.

Configure The Launch Theme

Create a starting theme in res/values/themes.xml. The postSplashScreenTheme item tells Android which theme to apply after the launch screen disappears.

<style name="Theme.SampleApp.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/teal_700</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
    <item name="postSplashScreenTheme">@style/Theme.SampleApp</item>
</style>

Use a drawable designed for the splash screen rather than placing a detailed photograph or a tiny text logo inside it. Android may mask the icon into a circular or adaptive shape. A simple mark remains recognisable on both compact phones and large tablets.

Set the starting theme on the launcher activity in AndroidManifest.xml:

<application
    android:theme="@style/Theme.SampleApp">

    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:theme="@style/Theme.SampleApp.Starting">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

The activity theme is more specific than the application theme, so Android uses Theme.SampleApp.Starting during launch and switches to Theme.SampleApp after startup. Keep the background colour consistent with the first screen to prevent a visible flash during the transition.

Add Motion To The First Screen

The Android 12 system splash handles the launch icon, while a separate animation can make the first activity feel polished. Add an ImageView or brand mark to activity_main.xml and animate it after setContentView.

<ImageView
    android:id="@+id/brandMark"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:contentDescription="@string/app_name"
    android:src="@drawable/ic_launcher_foreground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

The following Kotlin code combines a fade and a small scale effect. The post call waits until the view has been laid out, preventing animation values from being applied before Android knows the view dimensions.

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val brandMark = findViewById<ImageView>(R.id.brandMark)

        brandMark.alpha = 0f
        brandMark.scaleX = 0.85f
        brandMark.scaleY = 0.85f

        brandMark.post {
            brandMark.animate()
                .alpha(1f)
                .scaleX(1f)
                .scaleY(1f)
                .setDuration(350L)
                .setInterpolator(DecelerateInterpolator())
                .start()
        }
    }
}

Import android.view.animation.DecelerateInterpolator and the appropriate Android widget classes. A duration of around 250–450 milliseconds usually feels responsive. Avoid spinning, bouncing, or rapidly flashing effects because they can distract users and create accessibility concerns.

For a branded app used by customers from Perth to Parramatta, keep the motion consistent with the product’s purpose. A banking, transport, or health app generally benefits from restrained movement, while a game or entertainment app may support a more expressive animation.

Coordinate Loading And Navigation

Call installSplashScreen() before super.onCreate() so the AndroidX library can install its window behaviour at the correct stage. The screen should then move directly into the activity rather than navigating through a separate splash activity.

If the first screen genuinely requires a short operation, use a ViewModel to track it. For example, the splash can remain visible while a small local preference or cached configuration is read:

private var ready = false

override fun onCreate(savedInstanceState: Bundle?) {
    val splashScreen = installSplashScreen()

    splashScreen.setKeepOnScreenCondition {
        !ready
    }

    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    lifecycleScope.launch {
        loadLocalSettings()
        ready = true
    }
}

In production code, expose ready through observable state rather than a mutable activity property. Never hold the splash screen while waiting for a slow network request. A user opening an app on regional Australian mobile coverage should still reach the interface, even if remote content has not loaded yet.

Use the splash screen for initial setup only. Once the main activity is visible, show a progress indicator, skeleton layout, or empty state for slower tasks such as synchronising records, loading a SQLite database, or retrieving an account feed.

Test The Launch Experience

Test on Android 12 and newer devices as well as older versions supported by the project. Check cold starts, warm starts, dark mode, rotated layouts, and devices with reduced animation settings. The Android emulator can reveal timing problems, but a physical low-cost handset often gives a more realistic result.

The splash icon must have suitable contrast and safe spacing. Test it on light and dark backgrounds, and verify that text is not clipped by adaptive icon masking. Also check TalkBack labels, because decorative animation should not create repeated or confusing announcements.

A short checklist helps catch issues before publishing:

Visual and technical checks

  • The first screen appears without a blank white flash.
  • The launch icon remains clear after Android masking.
  • The animation finishes within a fraction of a second.
  • The app opens correctly after process recreation.

User experience checks

  • Startup works with offline mode enabled.
  • Reduced-motion settings do not cause confusing movement.
  • Network loading does not block the entire application.
  • The layout remains usable on small phones and tablets.

The following approaches suit different application requirements:

Approach Best For Strengths Limitations
AndroidX system splash Most modern apps Consistent Android behaviour and backward compatibility Limited control over the system launch animation
Separate splash activity Special routing requirements Can perform explicit navigation logic Adds startup complexity and may slow launch
Animated first-screen content Brand motion after launch Flexible fades, scales, and transitions Requires careful timing to avoid duplicating the splash
Static launch screen Utility and business apps Fast, simple, and accessible Provides less visual branding

For most Android Open Tutorials projects, combine the AndroidX system splash with a modest animation on the first activity. This gives users immediate feedback, keeps startup code maintainable, and produces a smooth experience across Australia’s varied devices and network conditions.