Share
Embed
Launch Screens: From a Tap to Your App
The launch screen is a user’s first experience of your application and, hence, should be designed with great care. In this talk, we will deep dive into the concept of launch screen, discover how to measure, debug & optimise them efficiently, and learn more about how to implement them correctly. In other words, this talk is all about discussing for ±45 min about screens displayed less than 5 seconds.
Cyril Mottier
June 17, 2016
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
108 slides
-
13 launches per month 23 % apps used only once
38 sec average interaction time Source: Mobile Life Research Centre, University of Stockholm & Localytics -
Placeholder UI /ˈpleɪshəʊldə(r) juː-aɪ/ Display core structural elements (status bar,
app bar, etc.) without content until the app has loaded. -
Branded launch /ˈbrændɪd lɔːntʃ/ Display your logo or other elements
that improve brand recognition to portray a brand while the app is loading. -
Source: iOS Human Interface Guidelines, Apple If you think that
following these guidelines will result in a plain, boring launch image, you’re right. Remember, the launch image doesn’t provide you with an opportunity for artistic expression. It’s solely intended to enhance the user’s perception of your app as quick to launch and immediately ready for use. “ -
User taps on icon Timeline of a launch 1 2
Fit to screen animation starts 3 4 5 -
User taps on icon Timeline of a launch 1 2
Fit to screen animation starts 3 4 5 Fit to screen animation ends -
User taps on icon Timeline of a launch 1 2
Fit to screen animation starts 3 4 5 Fit to screen animation ends Window switching starts -
User taps on icon Timeline of a launch 1 2
Fit to screen animation starts 3 4 5 Fit to screen animation ends Window switching starts App content finishes loading -
User taps on icon Timeline of a launch 1 2
Fit to screen animation starts 3 4 5 Fit to screen animation ends Window switching starts App content finishes loading -
1 2 3 4 5 Launcher & Intent triggering Entering
animation Static launch screen Content switching / fading Application fully drawn 1 2 3 4 5 -
1 2 3 5 System App Launcher & Intent triggering
Entering animation Static launch screen Content switching / fading Application fully drawn 1 2 3 4 5 4 -
1 Load and launch the app 2 Display a starting/preview
window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
1 Load and launch the app 2 Display a starting/preview
window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
System 1 Load and launch the app 2 Display a
starting/preview window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
System App 1 Load and launch the app 2 Display
a starting/preview window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
System App Cold start 1 Load and launch the app
2 Display a starting/preview window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
System App Warm start 1 Load and launch the app
2 Display a starting/preview window 3 Create the app process 4 Create the app object 5 Launch the main thread 6 Create the main activity 7 Inflate views 8 Lay out the screen 9 Perform the initial draw -
PhoneWindowManager.java Context context = mContext; try { context = context.createPackageContext(packageName,
0); context.setTheme(theme); } catch (PackageManager.NameNotFoundException e) { // Ignore } final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); -
PhoneWindowManager.java Context context = mContext; try { context = context.createPackageContext(packageName,
0); context.setTheme(theme); } catch (PackageManager.NameNotFoundException e) { // Ignore } final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); Create Context for the started application context = context.createPackageContext(packageName, 0); -
PhoneWindowManager.java Context context = mContext; try { context = context.createPackageContext(packageName,
0); context.setTheme(theme); } catch (PackageManager.NameNotFoundException e) { // Ignore } final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); Set the target theme context.setTheme(theme); -
PhoneWindowManager.java Context context = mContext; try { context = context.createPackageContext(packageName,
0); context.setTheme(theme); } catch (PackageManager.NameNotFoundException e) { // Ignore } final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); Create new Window and set it up final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params -
PhoneWindowManager.java Context context = mContext; try { context = context.createPackageContext(packageName,
0); context.setTheme(theme); } catch (PackageManager.NameNotFoundException e) { // Ignore } final PhoneWindow win = new PhoneWindow(context); win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); win.setFlags(/*...*/); final WindowManager.LayoutParams params = win.getAttributes(); // Tweak params ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)). addView(win.getDecorView(), params); Display the newly created Window -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } reportFullyDrawn(); } // ... } -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } reportFullyDrawn(); } // ... } reportFullyDrawn(); -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } reportFullyDrawn(); } // ... } SecurityException on KitKat… reportFullyDrawn(); -
public final class ActivityCompatAdditions { private static final Impl
IMPL; static { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { IMPL = new LollipopImpl(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { IMPL = new KitKatImpl(); } else { IMPL = new BaseImpl(); } } private ActivityCompatAdditions() { // No instances } public static void reportFullyDrawn(Activity activity) { IMPL.reportFullyDrawn(activity); } private interface Impl { void reportFullyDrawn(Activity activity); } -
private static final class BaseImpl implements Impl { @Override public
void reportFullyDrawn(Activity activity) { // No-op } } private static final class KitKatImpl implements Impl { @Override @TargetApi(Build.VERSION_CODES.KITKAT) public void reportFullyDrawn(Activity activity) { try { activity.reportFullyDrawn(); } catch (SecurityException se) { // Prevent an Exception on KitKat } } } private static final class LollipopImpl implements Impl { @Override @TargetApi(Build.VERSION_CODES.KITKAT) public void reportFullyDrawn(Activity activity) { activity.reportFullyDrawn(); } } } -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } } // ... } reportFullyDrawn(); -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } } // ... } reportFullyDrawn(); -
public class LaunchTimeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void> { private
static final int LOADER_YO = 0xcafe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_time); getSupportLoaderManager().initLoader(LOADER_YO, null, this); } @Override public void onLoadFinished(Loader<Void> loader, Void data) { switch (loader.getId()) { case LOADER_YO: // ... break; } } // ... } ActivityCompatAdditions.reportFullyDrawn(this); -
$ adb logcat | grep “ActivityManager” ActivityManager: Displayed com.launchtime/.LaunchTimeActivity: +666ms
ActivityManager: Fully drawn com.launchtime/.LaunchTimeActivity: +1s440ms API 19+ -
$ adb shell am start -W com.launchtime/.LaunchScreenActivity Starting: Intent {
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.launchtime/.LaunchScreenActivity } Status: ok Activity: com.launchtime/.LaunchScreenActivity ThisTime: 2426 TotalTime: 2426 WaitTime: 2488 Complete -
public class LazyProvider extends ContentProvider { private static final
int MODEL = 101; private static final int MODEL_ID = 102; private static final UriMatcher URI_MATCHER; static { URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER.addURI(LazyContract.AUTHORITY, "/model", MODEL); URI_MATCHER.addURI(LazyContract.AUTHORITY, "/model/#", MODEL_ID); // ... } private SQLiteOpenHelper mOpenHelper; @Override public boolean onCreate() { mOpenHelper = new LoadOpenHelper(getContext()); return true; } // ... } LazyProvider.java -
public class LazyProvider extends ContentProvider { private static final
int MODEL = 101; private static final int MODEL_ID = 102; private static final UriMatcher URI_MATCHER; static { URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER.addURI(LazyContract.AUTHORITY, "/model", MODEL); URI_MATCHER.addURI(LazyContract.AUTHORITY, "/model/#", MODEL_ID); // ... } private SQLiteOpenHelper mOpenHelper; @Override public boolean onCreate() { mOpenHelper = new LoadOpenHelper(getContext()); return true; } // ... } LazyProvider.java private static final UriMatcher URI_MATCHER; Created at class loading but used only in CRUD… -
public abstract class LazyGetter<T> { private final AtomicReference<Optional<T>> mCachedValue
= new AtomicReference<>(Optional.<T>empty()); public final T get() { Optional<T> value = mCachedValue.get(); if (!value.isPresent()) { synchronized (mCachedValue) { value = mCachedValue.get(); if (!value.isPresent()) { mCachedValue.set(Optional.ofNullable(initialValue())); } } } return mCachedValue.get().get(); } protected abstract T initialValue(); } LazyGetter.java -
public class LazyProvider extends ContentProvider { private static final
int MODEL = 101; private static final int MODEL_ID = 102; private static final LazyGetter<UriMatcher> URI_MATCHER = new LazyGetter<UriMatcher>() { @Override protected UriMatcher initialValue() { final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(LazyContract.AUTHORITY, "/model", MODEL); uriMatcher.addURI(LazyContract.AUTHORITY, "/model/#", MODEL_ID); // ... return uriMatcher; } }; // ... } LazyProvider.java -
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.cyrilmottier.android.launchtime" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:theme="@style/Theme.LaunchTime"> <activity android:name=".LaunchScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> AndroidManifest.xml -
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.cyrilmottier.android.launchtime" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:theme="@style/Theme.LaunchTime"> <activity android:name=".LaunchScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Default theme applies to all Activities AndroidManifest.xml android:theme="@style/Theme.LaunchTime"> -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.LaunchTime" parent="android:Theme.Material.Light.DarkActionBar"> <item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorAccent">@color/colorAccent</item> <item name="android:windowBackground">@color/appBackground</item> </style> </resources> values/themes.xml -
<?xml version="1.0" encoding="utf-8"?> <resources> <attr format="reference" name="ltRuntimeTheme" />
</resources> values/attrs.xml -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name=“PreviewTheme.LaunchTime" parent=“android:Theme.Holo.Light.DarkActionBar"> <item
name=“android:actionBarSize"> @dimen/abc_action_bar_default_height_material </item> <item name="android:actionBarStyle">@style/PreviewWidget.ActionBar</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values/themes_preview.xml -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name=“PreviewTheme.LaunchTime" parent=“android:Theme.Holo.Light.DarkActionBar"> <item
name=“android:actionBarSize"> @dimen/abc_action_bar_default_height_material </item> <item name="android:actionBarStyle">@style/PreviewWidget.ActionBar</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values/themes_preview.xml <item name=“android:actionBarSize"> @dimen/abc_action_bar_default_height_material </item> Force pre-Lollipop ActionBars height to 48 / 56 / 64dp -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name=“PreviewTheme.LaunchTime" parent=“android:Theme.Holo.Light.DarkActionBar"> <item
name=“android:actionBarSize"> @dimen/abc_action_bar_default_height_material </item> <item name="android:actionBarStyle">@style/PreviewWidget.ActionBar</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values/themes_preview.xml <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> Define the theme to use at runtime -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PreviewWidget.ActionBar" parent=“android:Widget.Holo.Light.ActionBar.Solid.Inverse"> <item
name="android:background">@color/colorPrimary</item> <item name=“android:displayOptions">showTitle</item> </style> </resources> values/styles_preview.xml -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PreviewTheme.LaunchTime" parent=“android:Theme.Material.Light.DarkActionBar"> <item
name="android:colorPrimary">@color/colorPrimary</item> <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorAccent">@color/colorAccent</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values-v21/themes_preview.xml -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PreviewTheme.LaunchTime" parent=“android:Theme.Material.Light.DarkActionBar"> <item
name="android:colorPrimary">@color/colorPrimary</item> <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorAccent">@color/colorAccent</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values-v21/themes_preview.xml parent=“android:Theme.Material.Light.DarkActionBar" Use Theme.Material on v-21+ devices -
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PreviewTheme.LaunchTime" parent=“android:Theme.Material.Light.DarkActionBar"> <item
name="android:colorPrimary">@color/colorPrimary</item> <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorAccent">@color/colorAccent</item> <item name="android:windowBackground">@color/appBackground</item> <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> </style> </resources> values-v21/themes_preview.xml Define the theme to use at runtime <item name=“ltRuntimeTheme">@style/Theme.LaunchTime</item> -
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.cyrilmottier.android.launchtime" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:theme="@style/PreviewTheme.LaunchTime"> <activity android:name=".LaunchScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> AndroidManifest.xml -
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.cyrilmottier.android.launchtime" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:theme="@style/PreviewTheme.LaunchTime"> <activity android:name=".LaunchScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> AndroidManifest.xml android:theme="@style/PreviewTheme.LaunchTime" Tell the system to use a temporary preview theme -
public final class ThemeUtils { private ThemeUtils() { // No
instances } @UiThread public static void ensureRuntimeTheme(Context context) { final TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.ltRuntimeTheme, tv, true); if (tv.resourceId <= 0) { throw new IllegalArgumentException("ltRuntimeTheme " + "not defined in the preview theme"); } context.setTheme(tv.resourceId); } } ThemeUtils.java -
public class LaunchScreenActivity extends AppCompatActivity { @Override protected void
onCreate(Bundle savedInstanceState) { ThemeUtils.ensureRuntimeTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_screen); // ... } } LaunchScreenActivity.java -
public class LaunchScreenActivity extends AppCompatActivity { @Override protected void
onCreate(Bundle savedInstanceState) { ThemeUtils.ensureRuntimeTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_screen); // ... } } LaunchScreenActivity.java Inherit AppCompatActivity to get AppCompat behaviour public class LaunchScreenActivity extends AppCompatActivity { -
public class LaunchScreenActivity extends AppCompatActivity { @Override protected void
onCreate(Bundle savedInstanceState) { ThemeUtils.ensureRuntimeTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch_screen); // ... } } LaunchScreenActivity.java ThemeUtils.ensureRuntimeTheme(this); Dynamically switch to the runtime theme