Home / IOS Development / An updated look at the launch of a Splash Screen digital product development agency

An updated look at the launch of a Splash Screen digital product development agency


Splash screens are a great deal for Android developers. In fact, BNR’s VP of Engineering, Chris Stewart, wrote our original Splash Screens the Right Way blog post over five years ago, and it’s still our most popular post.

We aim to update the implementation with modern Android practices and to fix a bug in the original post. The overall implementation of the splash screen is the same, but there are some considerations to make when navigating. If you are interested, I uploaded some sample project code on Github.

Before you begin, the official material name for a splash screen is now Launch Screen. And although there are several types of home screens, we will focus on one that shows the app icon when the app process is first loaded.

To fix a bug

Configuring the background for the home screen works in the same way as the original post. An XML drawing in the background is created and set as the window background for a home screen specific theme.

The original implementation explained the background as follows:



This no longer works for newly created Android apps for an interesting reason.

The tag expects a picture @drawable resource, but it does not allow specifying an XML-drawing source file. When a newer Android app is created, mipmap The launcher icons include a vector version which is an XML file.

This is why some people encounter this problem when creating a home screen using the original blog post. Since one of the launch icons is an XML file, is tag throws an exception. When you try to run the app in this configuration, this error is logged:

2020-09-15 13:14:18.365 25218-25218/com.example.splashscreen E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.splashscreen, PID: 25218
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.splashscreen/com.example.splashscreen.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.example.splashscreen:drawable/background_splash with resource ID #0x7f07005f
    Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.splashscreen:drawable/background_splash with resource ID #0x7f07005f
    Caused by: android.content.res.Resources$NotFoundException: File res/drawable/background_splash.xml from drawable resource ID #0x7f07005f
    Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8:  requires a valid 'src' attribute
2020-09-15 13:14:18.365 25218-25218/com.example.splashscreen E/AndroidRuntime:     at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:775)

The original blog post was created before vector resources were available on Android, so all launch icons are images, which means no errors are thrown off keywords.

Fixing this for apps with vector starter icons requires you to delete mark and move the attribute and gravity attributes to keywords.



Start screen implementation

With the resource exception handled, the launch screen implementation is next. A lot of this is similar to the previous post, so I will breeze through it.

The first step is to create a custom theme for the home screen.

The style is then applied to tag i AndroidManifest.xml.



Modernization issues

In the spirit of modernizing the trial app, my first attempt at home screen navigation involved adding the navigation component. This meant adding the addiction app/build.gradle file, declare a navigation graph resource and add the destinations. The LaunchActivity was declared the home destination that has an action to go to MainActivity.

This quickly revealed a problem. To be able to navigate from an activity, findNavController(view: View) function is called passing in a sight that is one NavHost or is within a NavHost. Normally this is not a problem for most activities because they have a vision to set up and display for the user.

For LaunchActivity, it has no view since it is just waiting onCreate() the function to be dialed before navigating to another activity. Use the navigation component to navigate from LaunchActivity would require creating a layout file that contained a navigation host, and setting up the layout in LaunchActivitys onCreate() function, access to NavController from the view, then use it to navigate to the next screen.

The problem with this implementation is speed. As soon LaunchActivity is ready, it should immediately navigate the user to the next activity. Inflates a view and grabs NavController takes time to get the user to see the launch image longer than necessary.

For this reason, the navigation component should not used to perform navigation from LaunchActivity. Use manual navigation with startActivity() is faster and more concise.

class LaunchActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        // Send user to MainActivity as soon as this activity loads
        val intent = Intent(this, MainActivity::class.java)

        // remove this activity from the stack

Another assessment

A common idea for launch screens is to perform app setup when the activity starts and navigate when the installation is complete. This sounds like a good idea because there may be certain components an app needs on the main screen, so setting them up in the launch activity seems like an obvious choice. Unfortunately, there is a problem with this.

If the app is thrown out of memory while in the background, the system tracks the activities of the task so that it can recreate them when the user returns to the app. The problem is that the launch activity is complete when the user leaves, which means that the system will not recreate the activity when the app is restarted. This means that any installation code will not run and that the app may end up in poor condition.

This does not necessarily mean some the installation code in the launch activity is intended for errors and crashes. Tasks such as updating data from a server may be fine, as long as the app can handle a situation where the data is not on other screens. If the other screens themselves can request the data again, it is no problem to have that kind of logic in the launch activity.

Where problems occur, it is in situations where critical components are set up in the launch activity, and other monitors expect these components to be initialized without first checking. For example, if an app uses the launch activity to initialize its Dagger component and the other activities expect it to be present, the app will not work when re-initialized by the system because the new app process will not have a new component available.

For this reason, a critical setup code should occur in one Application subclass. This ensures that the installation code is executed when the application process is loaded into memory, so that the components are available to the rest of the app.

For more information, check out Andrew Bailey’s Falsehoods Android Developers Believe about Lifecycles talk from Droidcon Online.


Source link