

# Application lifecycle events in Amazon Connect Agent Workspace
<a name="integrating-with-agent-workspace-lifecycle-events"></a>

There are lifecycle states that an app can move between from when the app is initially opened to when it is closed in the Amazon Connect agent workspace. This includes the initialization handshake that the app goes through with the agent workspace after it has loaded to establish the communication channel between the two. There is another handshake between the agent workspace and the application when the app will be shutdown. An application can hook into `onCreate` and ` onDestroy` when calling `AmazonConnectApp.init()`.

The following section describe the create and destroy events in the Amazon Connect agent workspace.

**Topics**
+ [Create event](integrating-with-agent-workspace-lifecycle-events-create.md)
+ [Destroy event](integrating-with-agent-workspace-lifecycle-events-destroy.md)

# The create event in Amazon Connect Agent Workspace
<a name="integrating-with-agent-workspace-lifecycle-events-create"></a>

The create event in the Amazon Connect agent workspace results in the ` onCreate` handler passed into the `AmazonConnectApp.init()` to be invoked. ` Init` should be called in an application once it has successfully loaded and is ready to start handling events from the workspace. The create event provides the *appInstanceId* and the * appConfig* .
+ **appInstanceId**: The ID for this instance of the app provided by the workspace.
+ **appConfig**: The application configuration being used by the instance for this app.
+ **contactScope**: Provides the current ` contactId` if the app is opened during an active contact.

# The destroy event in Amazon Connect Agent Workspace
<a name="integrating-with-agent-workspace-lifecycle-events-destroy"></a>

The destroy event in the Amazon Connect agent workspace will trigger the ` onDestroy` callback configured during `AmazonConnectApp.init()`. The application should use this event to clean up resources and persist data. The agent workspace will wait for the application to respond that it has completed clean up for a period of time.