目录

UI Context Debugging

This section describes how to resolve text display abnormalities caused by invalid UIContext. Using an invalid UIContext object (typically resulting from destruction of the corresponding UI instance) may cause subsequent UI operations to fail. This issue is common in multi-window scenarios. Starting from API version 12, it can also occur when the process cache is enabled via setSupportedProcessCache and the process is then rapidly restarted.

Identifying UIContext Errors

Invalid UIContext may occur in the following scenarios:

Instance Details

Error messages from some instance-related APIs include information about the corresponding instance. Only instances in the cache list will output detailed information. The cache list stores only information about destroyed instances.

  • The current cache list size is 10, and the least recently used (LRU) mechanism is used for eviction.

[h2]Cache Hit

When an abnormal instance hits the cache, the detailed information is output in the following format:

DestroyedUIContextCacheInfo: instanceInfo: [instanceId:<instanceId_>, createTime:<createTime_>, destroyTime:<destroyTime_>], windowInfo: [windowId: <windowId_>, windowName: <windowName_>]

[h2]Cache Miss

When the requested instance does not exist in the cache (either never cached or evicted due to exceeding cache size), the detailed information is output in the following format:

InstanceId not found in destroyed cache.

[h2]Full Message Example

Detailed information of a cached destroyed instance is output in the following format, including the instance ID, creation time, destruction time, window ID, and window name fields:

UI execution context not found.InstanceId: 100001,

Reason to get the instance: The instance is determined by the caller,

DestroyedUIContextCacheInfo: instanceInfo: [instanceId:100001, createTime:2026-04-14 10:30:00.123, destroyTime:2026-04-14 10:35:22.456], windowInfo: [windowId: 1001, windowName: EntryAbility]

The parameters in the preceding code are described as follows.

Table 2 Description of fields in a full message

Field Description
instanceId Instance ID. The value is allocated by the system when the instance is created.
Reason to get the instance Reason for obtaining the instance. For details, see Table 3.
createTime Time when the instance is created.
destroyTime Time when the instance is destroyed.
windowId ID of the window corresponding to the instance.
windowName ID of the window corresponding to the instance.

Table 3 Description of the reasons for instance specification

Description Description
The instance is determined by the caller. The instance ID is explicitly specified during the call. Generally, the application specifies the instance ID through the UIContext API.
No specific instance was specified, so the most recently active instance was retrieved. If no instance ID is explicitly specified, the system returns the most recently active instance.
No specific instance was specified, return the foreground instance. If no instance ID is explicitly specified, the system returns the instance running in the foreground.
No specific instance was specified, return the only remaining instance. If no instance ID is explicitly specified, the system returns the only instance (when only one UI instance exists).
No specific instance was specified, using default. If no instance ID is explicitly specified, the default instance (the last created instance) is used.
No valid instance exists. No valid UI instance exists.

Resolving Display Abnormalities Caused by UIContext Errors

Symptom

The following situations may occur:

  1. When the setStyledString method is used to set the font size, the font size does not change as expected.
  2. When a UIContext member method is used, the UI does not respond or is displayed incorrectly.

Solution

Obtain a valid UIContext object using one of these methods: