openharmony 鸿蒙 arkts-wrong-uicontext-debug

2026-08-25 浏览 (1)

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:

  • JavaScript exception: "Node Constructor error, param uiContext error".

    This error occurs when an invalid UIContext is used in custom nodes, potentially causing subsequent UI operations to be incorrectly associated with the invalid context.

  • Instance status update logs with context instance ID values greater than or equal to 100000 and less than 1000000.

    The format of the instance status update log is as follows:

    ({currentId}:{trackedId}:{trackedReason})][{bundleName}][{moduleName}][{thisInstanceId}]: window {status}

    Fields in the log |Field|Type|Typical Value|Description| |----|----|----|----| |{currentId}|Integer|-1|Context instance ID. In a normal application, this value is negative.| |{trackedId}|Integer|100000|ID of the indirectly traced instance. Usually a positive number; can be ignored.| |{trackedReason}|String|singleton|Reason for indirect tracing; can be ignored.| |{bundleName}|String|com.example.helloworld|Bundle name of the application.| |{moduleName}|String|entry|Module name of the current module.| |{thisInstanceId}|Positive number|100000|Notified UI instance ID.| |{status}|Status of the notified instance|focus|Available values:
    - focus: focused
    - unfocus: unfocused
    - foreground: foreground
    - background: background
    - destroy: destroyed|

    Use this regular expression to match relevant logs:

    \(-?\d+:-?\d+:(scope|active|default|singleton|foreground|undefined)\)\] \[[a-z0-9.]+\]\[[a-zA-Z][0-9a-zA-Z_.]*\]\[\d+\]: window (focus|unfocus|foreground|background|destroy)

    Example Analysis

    • Normal log:

      (-2:100000:singleton)] [com.example.helloworld][entry][100000]: window foreground

    • Abnormal log:

      (100000:100000:scoped)] [com.example.helloworld][entry][100001]: window background

      This log indicates an error tracing the UI instance with ID 100000.

    • Destruction log:

      (-2:100000:singleton)] [com.example.helloworld][entry][100000]: window destroy

      This log indicates that the UI instance with ID 100000 has been destroyed; subsequent UI operations that rely on its context may be affected.

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:

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-common-components-text-input

openharmony 鸿蒙 arkts-select-component-faq

openharmony 鸿蒙 arkui-overview

openharmony 鸿蒙 js-framework-syntax-css

openharmony 鸿蒙 arkts-popup-and-menu-components-popup

openharmony 鸿蒙 arkts-navigation-animation-faq

openharmony 鸿蒙 arkts-rotation-transition-animation

openharmony 鸿蒙 ndk-inspector-component-observer

openharmony 鸿蒙 arkts-popup-and-menu-components-uicontext-popup

openharmony 鸿蒙 arkts-styled-string

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/aU4OX7gC