Optimize application startup times
Report when your application finishes initialization and analyze startup data to optimize the application startup process.
Read time 2 minutesLast updated a day ago
Android can optimize the application startup process to reduce the time it takes for the application to become interactive. To enable this optimization, report when your application finishes initialization and is ready for user interaction. Android uses this information to prioritize tasks that run before initialization completes. Android also records diagnostic data for each startup, which you can retrieve to analyze how and when the application started.
Report application startup completion
To report to Android that application startup is complete, use . By default, Unity calls this method when the first scene loads, before . An application can perform additional tasks before it becomes interactive, such as loading resources before rendering to the screen. In this case, call on the frame when the application becomes interactive. If your code calls , Unity doesn't call the method automatically when the first scene loads.
DiagnosticsReporting.CallReportFullyDrawnAwakeDiagnosticsReporting.CallReportFullyDrawnDiagnosticsReporting.CallReportFullyDrawnRetrieve application startup information
Android records diagnostic data for each application startup. You can use this data to run analytics and diagnostics, optimize startup times, and track how different settings affect startup performance.
To retrieve the startup records that Android stores for your application:
-
Callto get an array of
ApplicationStartInfoProvider.GetHistoricalProcessStartReasonsrecords. To limit the number of records that the method returns, pass theIApplicationStartInfoparameter. SetmaxNumtomaxNumto return all records.0 -
Read the properties of each record that you want to analyze, such as,
reason, andstartType.startupTimestamps
GetHistoricalProcessStartReasonsThe following code example retrieves all startup records that Android stores for the application:
using UnityEngine;using UnityEngine.Android;public class LogApplicationStartInfoExample : MonoBehaviour{ private void Start() { LogApplicationStartInfo(); } private static void LogApplicationStartInfo() { // Get all available startup records sorted from most recent to least recent. #if UNITY_ANDROID && !UNITY_EDITOR IApplicationStartInfo[] results = ApplicationStartInfoProvider.GetHistoricalProcessStartReasons(); int total = results.Length; for (int i = 0; i < total; i++) { IApplicationStartInfo result = results[i]; if (result != null) { Debug.Log($"[ApplicationStartInfo] [{i + 1}/{total}]\n{result.ToString()}\n"); } } #else Debug.Log("[ApplicationStartInfo] Historical start reasons are only available on Android devices."); #endif }}