Disabling the Preview(Start) Window in Android

29 / Jun / 2016 by Noor Alam 0 comments

When we tap on an app icon to launch the app, first we see a white or grey (depending on the default theme) screen for a second or two, before actual application launch.

white_screen                          calendar_home

 

This is an annoying and undesirable situation which we can handle following the process explained in this blog.

Why does it happen?

When we start a new application on Android basically it needs a new process to be created which will run a new instance of a Dalvik VM. Once started, the Dalvik VM will, in turn, initialise a thread in which most of your code will be executed. This thread is called UI thread or Main thread. But in Android, for every app launch, initialising a process running a new instance of Dalvik VM from scratch takes time. Android invented a new way of reducing this time called Zygote.

The Zygote technique creates an initial process at boot time running a Dalvik VM. This instance of Dalvik VM preloads a bunch of classes, Drawables and Colour State Lists from the SDK and is used as the seed process from which all instances will be derived. Now spawning a new ready-to-use process in Android simply requires forking the Zygote process which is way more efficient and time saving than creating a new process from scratch.

Zygote is an important invention in Android. It minimises the memory usage and reduces the amount of time required to start a new process.

Although, application launching is lightening fast, Android still require some time to load some data from your application (classes, resources, etc). In order to avoid bumping and visually respond to user as soon as possible, the system displays a temporary window called the “Starting Window” also known as the “Preview Window”.

The purpose of preview windows is to give the user immediate feedback that the app launched and it also gives the app time to initialise itself. When your app is ready to run, the system removes the preview window and displays your app’s windows and views. As a result, none of your Java code is executed when the starting window is displayed.

Starting windows does nothing and displays a minimal UI. It is of type TYPE_APPLICATION_STARTING, non focusable, non touchable and only displayed when the started Activity belongs to an application whose process is not started yet. As a result, starting windows are generally shown before actually displaying the Activity whose category is android.intent.category.LAUNCHER. However, due to the Android multitasking model, starting windows can also be displayed when restoring an Activity. This is why do not consider starting windows as splash screens.

app launch summary

 

Disabling the Starting(Preview) Window

In order to disable the Starting Window or Preview Window, create the following theme in your styles.xml file

[sourcecode language=”xml” wraplines=”false” collapse=”false”]

<style name="Theme.NoPreviewWindow" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
</style>

[/sourcecode]

or

[sourcecode language=”xml” wraplines=”false” collapse=”false”]

<style name="Theme.NoPreviewWindow" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>

[/sourcecode]

and set it in your launcher activity

[sourcecode language=”java” wraplines=”false” collapse=”false”]

<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:theme="@style/Theme.NoPreviewWindow"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

[/sourcecode]

and you are done!

Though it is easy to remove the Starting Window and it feels like we are directly entering into the app bypassing the Preview Window, in fact app still takes same amount of time to launch the app.

Disabling starting window also removes its main advantage,: simulation of instant application launching. That is why It is highly recommended not to disable starting window unless really necessary (this is mostly only necessary in games based on Open GL ES).

Preview Window is to fake a fast launching app while the system loads up your application process and make your app launch as graphically pleasant as possible to your users.

Many Applications prefer not to disable the Preview Window for example Play Store, WhatsApp, Calculator, Settings etc. Instead they change its them to match the theme of the Launcher Activity to show seamless and smooth transition from the Preview Window to the app.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *