Skip to content

Application: inactive event ​

The inactive event fires when the app is about to leave the active state.

Syntax ​

application.addEventListener('inactive', (event) => { })

Event object ​

Event. target is application. Not cancelable.

When it fires ​

  • When the user goes to the Home Screen or switches to another app, followed by background.
  • It also fires for an incoming call or when Notification Center is pulled down; the app may then return directly to the active state without firing background. So use background, not this event, to save data.
  • When the event arrives, state is still the old value 'active' (verified by testing).
  • The callback runs later; see How the runtime works.

Examples ​

js
application.addEventListener('inactive', (e) => {
  console.log(e.type, 'state is now', application.state);
});

Result: prints inactive state is now active when the user goes to the Home Screen.

Corresponding iOS API ​

UIApplicationWillResignActiveNotification.

See also ​