{"id":36796,"date":"2016-06-29T15:41:18","date_gmt":"2016-06-29T10:11:18","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=36796"},"modified":"2016-06-30T09:32:26","modified_gmt":"2016-06-30T04:02:26","slug":"disabling-the-preview-or-start-window-in-android","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/disabling-the-preview-or-start-window-in-android\/","title":{"rendered":"Disabling the Preview(Start) Window in Android"},"content":{"rendered":"<p>When we tap on an app icon to launch the\u00a0app, first we see a white or grey (depending on the default theme) screen for a second or two, before actual application launch.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-36823\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/white_screen.png\" alt=\"white_screen\" width=\"333\" height=\"592\" \/>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-36824\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/calendar_home.png\" alt=\"calendar_home\" width=\"340\" height=\"604\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>This is an\u00a0annoying and undesirable situation which we can handle following the process explained in this blog.<\/p>\n<h1><strong>Why does it happen?<\/strong><\/h1>\n<p>When we start a new <a title=\"android application development services\" href=\"http:\/\/www.tothenew.com\/mobile-android-application-development-services\">application on Android<\/a> basically it needs a new process to be created\u00a0which 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.\u00a0But 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 <strong>Zygote<\/strong>.<\/p>\n<p>The Zygote technique creates an initial process at boot time running\u00a0a 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\u00a0spawning 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.<\/p>\n<p>Zygote is an important invention\u00a0in Android. It minimises the memory usage and reduces the amount of time required to start a new process.<\/p>\n<p>Although, application launching is lightening\u00a0fast, 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 \u201c<strong>Starting Window<\/strong>\u201d also known as the \u201c<strong>Preview Window<\/strong>\u201d.<\/p>\n<p>The purpose of preview windows is to give the user immediate feedback that the app launched and\u00a0it also gives the\u00a0app time to initialise itself. When your app is ready to run, the system removes the preview window and displays your app\u2019s windows and views. As a result, none of your Java code is executed when the starting window is displayed.<\/p>\n<p>Starting windows does nothing and displays a\u00a0minimal UI. It is\u00a0of 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\u00a0shown 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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-36833 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/app-launch-summary.jpg\" alt=\"app launch summary\" width=\"683\" height=\"467\" \/><\/p>\n<p>&nbsp;<\/p>\n<h1><strong>Disabling the Starting(Preview) Window<\/strong><\/h1>\n<p>In order to disable\u00a0the Starting Window or Preview Window, create the following theme in your\u00a0styles.xml file<\/p>\n<p>[sourcecode language=&#8221;xml&#8221; wraplines=&#8221;false&#8221; collapse=&#8221;false&#8221;]<\/p>\n<p>   &lt;style name=&quot;Theme.NoPreviewWindow&quot; parent=&quot;Theme.AppCompat.NoActionBar&quot;&gt;<br \/>\n        &lt;item name=&quot;android:windowIsTranslucent&quot;&gt;true&lt;\/item&gt;<br \/>\n   &lt;\/style&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p>or<\/p>\n<p>[sourcecode language=&#8221;xml&#8221; wraplines=&#8221;false&#8221; collapse=&#8221;false&#8221;]<\/p>\n<p>   &lt;style name=&quot;Theme.NoPreviewWindow&quot; parent=&quot;Theme.AppCompat.NoActionBar&quot;&gt;<br \/>\n        &lt;item name=&quot;android:windowDisablePreview&quot;&gt;true&lt;\/item&gt;<br \/>\n   &lt;\/style&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p>and set it in your\u00a0launcher activity<\/p>\n<p>[sourcecode language=&#8221;java&#8221; wraplines=&#8221;false&#8221; collapse=&#8221;false&#8221;]  <\/p>\n<p>        &lt;activity<br \/>\n            android:name=&quot;.activities.SplashActivity&quot;<br \/>\n            android:label=&quot;@string\/app_name&quot;<br \/>\n            android:theme=&quot;@style\/Theme.NoPreviewWindow&quot;<br \/>\n            android:screenOrientation=&quot;portrait&quot;<br \/>\n            &gt;<br \/>\n            &lt;intent-filter&gt;<br \/>\n                &lt;action android:name=&quot;android.intent.action.MAIN&quot;\/&gt;<br \/>\n                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;\/&gt;<br \/>\n            &lt;\/intent-filter&gt;<br \/>\n        &lt;\/activity&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p>and you are done!<\/p>\n<p>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.<\/p>\n<p>Disabling starting\u00a0window also removes its\u00a0main advantage,: simulation of\u00a0instant application launching. That is why\u00a0It is highly recommended\u00a0not to disable starting window unless really necessary (this is mostly only necessary in games based on Open GL ES).<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we tap on an app icon to launch the\u00a0app, first we see a white or grey (depending on the default theme) screen for a second or two, before actual application launch. \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 &nbsp; This is an\u00a0annoying and undesirable situation which we can [&hellip;]<\/p>\n","protected":false},"author":150,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":139},"categories":[518,1772],"tags":[3671,3672,3673,3670],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/36796"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/150"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=36796"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/36796\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=36796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=36796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=36796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}