The Application Launched/Closed trigger fires when an application becomes the foreground application (launched) or when it is no longer the foreground app (closed). This is useful for automating actions based on which app is currently in use.

Options

  • Application Launched - Trigger fires when the selected application becomes the foreground app
  • Application Closed - Trigger fires when the selected application is no longer the foreground app

Application Selection

After choosing the event type, you can specify which applications to monitor:

  • Select Applications - Choose specific applications from a searchable list. Multiple apps can be selected.
  • Enter Package Name - Manually enter a package name. Supports magic text for dynamic package names.
  • All Applications - Trigger fires for any application launch/close (excluding MacroDroid itself and system UI)

When selecting specific applications, you can:

  • Search for apps by name
  • Show non-launchable apps using the checkbox
  • Select multiple applications
  • Previously selected apps appear at the top of the list

Settings

  • Force legacy mode - Uses an older polling-based method instead of the Accessibility Service. This may be needed on some devices but is less efficient. When enabled, additional settings become available for API 21/22 compatibility.
  • Prevent notification interrupt - Available when using legacy mode on certain Android versions

Magic Text

When using the "Enter Package Name" option, you can use magic text to specify the package name dynamically. This allows for variable-based app detection.

The trigger also provides context information including the app name and package name that can be used in subsequent actions.

  • {app_package}
  • {app_name}

Examples

Example 1: Mute When Opening Video App

Triggers

Application Launched (YouTube)
Actions

Volume Change: Media Volume to 0

Example 2: Lock Screen When Leaving Banking App

Triggers

Application Closed (Banking App)
Actions

Screen Lock

Notes

  • By default, this trigger uses the Accessibility Service to detect foreground app changes, which is efficient and reliable
  • The legacy polling mode requires Usage Access permission on Android 5.1 (API 22) and above
  • When "Application Closed" macros are triggered, they are processed before "Application Launched" macros for the new foreground app
  • The trigger ignores soft input windows (keyboards) to avoid false triggers when the keyboard appears

Permissions Required

  • Accessibility Service - Required for the default (non-legacy) mode
  • Usage Access - Required for legacy mode on Android 5.1+

See Also