harmony 鸿蒙Lifecycle

  • 2023-10-30
  • 浏览 (162)

Lifecycle

Application lifecycle

You can define the following application lifecycle methods in the app.js file.

Attribute Type Description Called When
onCreate () => void Listens for application creation. The application is created.
onDestroy () => void Listens for application destruction. The application exits.

Page Lifecycle

You can define the following page lifecycle functions in the .js file of the page.

NOTE

To avoid affecting the page switching performance, do not perform complex, time-consuming operations in a lifecycle function.

Attribute Type Description Called When
onInit () => void Listens for page initialization. Page initialization is complete. This function is called only once in the page lifecycle.
onReady () => void Listens for page creation. A page is created. This function is called only once in the page lifecycle.
onShow () => void Listens for page display. The page is displayed.
onHide () => void Listens for page hiding. The page is hidden.
onDestroy () => void Listens for page destruction. The page is destroyed.

The lifecycle functions of page A are called in the following sequence:

  • Open page A: Call onInit(), onReady(), and onShow() in sequence.
  • Open page B on page A: onHide() -> onDestroy()
  • Go back to page A from page B: onInit() -> onReady() -> onShow()
  • Exit page A: onHide() -> onDestroy()
  • Hide page A: onHide()
  • Show background page A on the foreground: onShow()

img

你可能感兴趣的鸿蒙文章

harmony 鸿蒙JavaScript-compatible Web-like Development Paradigm (ArkUI.Lite)

harmony 鸿蒙Universal Attributes

harmony 鸿蒙Universal Events

harmony 鸿蒙Universal Styles

harmony 鸿蒙chart

harmony 鸿蒙image-animator

harmony 鸿蒙image

harmony 鸿蒙input

harmony 鸿蒙marquee

harmony 鸿蒙picker-view

0  赞