Skip to main content

AppLifecycleState

States that an application can be in once it is running.

Inherits: enum.Enum

Properties

  • DETACH - The application has exited, and detached all host views from the engine.
  • HIDE - The application is hidden.
  • INACTIVE - The application loses input focus.
  • PAUSE - The application is paused.
  • RESTART - The application is resumed after being paused.
  • RESUME - The application gains input focus.
  • SHOW - The application is shown.

Examples

Showcase

import flet as ft


def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

log = ft.Column(
spacing=4,
scroll=ft.ScrollMode.AUTO,
height=220,
)

def add_log(message: str):
log.controls.insert(0, ft.Text(message, size=12))
if len(log.controls) > 20:
log.controls.pop()
log.update()

def on_lifecycle(e: ft.AppLifecycleStateChangeEvent):
add_log(f"Received: {e.state.name}")

page.on_app_lifecycle_state_change = on_lifecycle

page.appbar = ft.AppBar(title="AppLifecycleState Showcase")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Text(
"Switch app focus/visibility to see lifecycle state changes."
),
ft.Text(
"Ex: minimize/restore app, switch tabs, or "
"background/foreground app.",
size=11,
),
ft.Row(
wrap=True,
spacing=8,
controls=[
ft.Container(
padding=ft.Padding.symmetric(horizontal=8, vertical=4),
border=ft.Border.all(1, ft.Colors.OUTLINE),
border_radius=12,
content=ft.Text(state.name, size=11),
)
for state in ft.AppLifecycleState
],
),
ft.Container(
width=720,
padding=12,
border=ft.Border.all(1, ft.Colors.RED),
border_radius=10,
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
content=log,
),
]
)
)
)


if __name__ == "__main__":
ft.run(main)

Properties

DETACHclass-attributeinstance-attribute

The application has exited, and detached all host views from the engine.

This callback is only called on iOS and Android.

HIDEclass-attributeinstance-attribute

The application is hidden.

On mobile platforms, this is usually just before the application is replaced by another application in the foreground.

On desktop platforms, this is just before the application is hidden by being minimized or otherwise hiding all views of the application.

On the web, this is just before a window (or tab) is hidden.

INACTIVEclass-attributeinstance-attribute

The application loses input focus.

On mobile platforms, this can be during a phone call or when a system dialog is visible.

On desktop platforms, this is when all views in an application have lost input focus but at least one view of the application is still visible.

On the web, this is when the window (or tab) has lost input focus.

PAUSEclass-attributeinstance-attribute

The application is paused.

On mobile platforms, this happens right before the application is replaced by another application.

On desktop platforms and the web, this function is not called.

RESTARTclass-attributeinstance-attribute

The application is resumed after being paused.

On mobile platforms, this happens just before this application takes over as the active application.

On desktop platforms and the web, this function is not called.

RESUMEclass-attributeinstance-attribute

The application gains input focus. Indicates that the application is entering a state where it is visible, active, and accepting user input.

SHOWclass-attributeinstance-attribute

The application is shown.

On mobile platforms, this is usually just before the application replaces another application in the foreground.

On desktop platforms, this is just before the application is shown after being minimized or otherwise made to show at least one view of the application.

On the web, this is just before a window (or tab) is shown.