Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetHistoricalProcessStartReasons(int)

Returns a list of ApplicationStartInfo records containing the reasons for the most recent app starts.
Read time 1 minuteLast updated 14 days ago

Definition

public static IApplicationStartInfo[] GetHistoricalProcessStartReasons(int maxNum = 0)

Parameters

maxNum

The maximum number of results to be returned. Set this to 0 to ignore this parameter and return all matching records.

Returns

Type

Description

IApplicationStartInfo[]An array of IApplicationStartInfo records matching the criteria, sorted in the order from most recent to least recent. Never null.

Remarks

For more information, refer to Android's documentation on getHistoricalProcessStartReasons. Available on Android API 35+. Returns an empty array on earlier versions.

Examples

using UnityEngine;using UnityEngine.Android;public class AppStartDiagnostics : MonoBehaviour{ void Start() { IApplicationStartInfo[] records = ApplicationStartInfoProvider.GetHistoricalProcessStartReasons(1); if (records.Length == 0) { Debug.Log("No start info available (requires Android API 35+)."); return; } IApplicationStartInfo info = records[0]; // Log core start properties. Debug.Log($"Process: {info.processName} (pid {info.pid})"); Debug.Log($"Reason: {info.reason}, type: {info.startType}, state: {info.startupState}"); Debug.Log($"Force-stopped before launch: {info.wasForceStopped}"); // Log the launch mode when the start was triggered by an activity launch. if (info.reason == StartReason.Launcher || info.reason == StartReason.StartActivity) Debug.Log($"Launch mode: {info.launchMode}"); // Calculate time to first frame; timestamps are clock-monotonic values in nanoseconds. if (info.startupTimestamps.TryGetValue(StartTimestamp.Launch, out long launchNs) && info.startupTimestamps.TryGetValue(StartTimestamp.FirstFrame, out long firstFrameNs)) { Debug.Log($"Time to first frame: {(firstFrameNs - launchNs) / 1_000_000} ms"); } }}