Jaa


WebUIApplication.BackgroundActivated Event

Definition

Invoked when the application is activated in the background.

public:
 static event BackgroundActivatedEventHandler ^ BackgroundActivated;
// Register
static event_token BackgroundActivated(BackgroundActivatedEventHandler const& handler) const;

// Revoke with event_token
static void BackgroundActivated(event_token const* cookie) const;

// Revoke with event_revoker
static WebUIApplication::BackgroundActivated_revoker BackgroundActivated(auto_revoke_t, BackgroundActivatedEventHandler const& handler) const;
public static event BackgroundActivatedEventHandler BackgroundActivated;
function onBackgroundActivated(eventArgs) { /* Your code */ }
Windows.UI.WebUI.WebUIApplication.addEventListener("backgroundactivated", onBackgroundActivated);
Windows.UI.WebUI.WebUIApplication.removeEventListener("backgroundactivated", onBackgroundActivated);
- or -
Windows.UI.WebUI.WebUIApplication.onbackgroundactivated = onBackgroundActivated;
Public Shared Custom Event BackgroundActivated As BackgroundActivatedEventHandler 

Event Type

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v7.0)

Remarks

BackgroundActivated is a special UWP background task that runs as a handler on the view thread (or background script, see below). Unlike a regular background task running on a worker thread, this provides access to the DOM and referenece to foreground views.

This event is the web app equivalent of the Windows.UI.Xaml Application.OnBackgroundActivated event. In the web app case specifically, if there is no running view thread (the app is not running), the event will activate the app's background script and fire there.

Similar to XAML, to denote a background script as background activation, a null taskEntryPoint is provided to BackgroundTaskBuilder. This background task is registered programmatically (rather than declared in the appxmanifest):

let builder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder();
builder.name = 'WwaHostBGActivated';
builder.setTrigger(new background.SystemTrigger(background.SystemTriggerType.timeZoneChange, false));
let backgroundTaskRegistration = builder.register();

Applies to