openharmony 鸿蒙 js-framework-lifecycle

2022-08-09 浏览 (975)

Lifecycle

Application Lifecycle

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

AttributeTypeDescriptionCalled When
onCreate() => voidListens for application creation.The application is created.
onShow6+() => voidListens for whether the application is running in the foreground.The application is running in the foreground.
onHide6+() => voidListens for whether the application is running in the background.The application is running in the background.
onDestroy() => voidListens for application uninstallation.The application exits.

Page Lifecycle

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

AttributeTypeDescriptionCalled When
onInit() => voidListens for page initialization.Page initialization is complete. This function is called only once in the page lifecycle.
onReady() => voidListens for page creation.A page is created. This function is called only once in the page lifecycle.
onShow() => voidListens for page display.The page is displayed.
onHide() => voidListens for page disappearance.The page disappears.
onDestroy() => voidListens for page destruction.The page is destroyed.
onBackPress() => booleanListens for the back button action.The back button is touched.
- true means that the page processes the return logic.
- false means that the default return logic is used.
- If no value is returned, the default return logic is used.
onActive()5+() => voidListens for page activation.The page is activated.
onInactive()5+() => voidListens for page suspension.The page is suspended.
onNewRequest()5+() => voidListens for a new FA request.The FA has been started and a new request is received.

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

  • Open page A: onInit() -> onReady() -> onShow()

  • Open page B on page A: onHide()

  • Go back to page A from page B: onShow()

  • Exit page A: onBackPress() -> onHide() -> onDestroy()

  • Hide page A: onInactive() -> onHide()

  • Show background page A on the foreground: onShow() -> onActive()

en-us_image_0000001267887881

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI

harmony 鸿蒙Atomic Service Full Screen Launch Component (FullScreenLaunchComponent)

harmony 鸿蒙Arc Button (ArcButton)

harmony 鸿蒙Animation Smoothing

harmony 鸿蒙Animation Overview

harmony 鸿蒙Frame Animation (ohos.animator)

harmony 鸿蒙Implementing Property Animation

harmony 鸿蒙Property Animation Overview

harmony 鸿蒙Dialog Box Overview

harmony 鸿蒙Blur Effect

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