---
title: "Application State Collection Methods"
slug: "application-state-collection-methods"
updated: 2020-04-16T20:15:37Z
published: 2020-04-16T20:15:37Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://onpremises.webtrends.help/llms.txt
> Use this file to discover all available pages before exploring further.

# Application State Collection Methods

Once your application is published out to Google Play and finally downloaded by app users, it is critically important to find out how your application really behaves in their hands. Whether the app runs without crashing on their device or how frequently your app is being viewed once it's been installed is vitally important information to be fed into the next development cycle of your application.

To find out how your application gets started, comes in and out of foreground, or gets terminated on a device, there are a number of methods available for monitoring. These methods can be implemented either automatically or manually depending upon the state of application you would like to monitor.

For example, if you'd like to automatically monitor when your app gets started, comes into the foreground or background, you must enable the following configuration by setting the value to `true` in your MyApp/res/values/webtrends.xml.

`&lt;string name="wt_dc_activity_automatics_enabled"&gt;true&lt;/string&gt;`

However, if you want to extend beyond scope of simply monitoring activity life cycles alone, you can also manually trigger events such as initial launch, normal exit or app terminated by error and etc.

---

## onActivityStart

The `onActivityStart` method automatically collects data when an activity starts if the application is extended with “WTApplication” and `Activity.onCreate` or `Activity.onStart` is executed.

This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`&amp;customKey=customValue`

#### Syntax

```
public void onActivityStart(String activityName, Map<String,String> customData)
```

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
WebtrendsDataCollector.getInstance().onActivityStart("Hello World Activity Start", customData);
```

#### Parameters

- `activityName`: Specifies an activity name associated with the end of user activity.
- `customData` (optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Throws

- `IllegalArgumentException`: Returned when an argument is malformed.

#### Webtrends Parameter Values

- `dcsuri`: /activity/start
- `WT.ti`: activityName
- `WT.pi`: activityName
- `WT.sys`: start
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.

---

## onActivityPause

The `onActivityPause` method automatically collects data when an activity is paused if the application is extended with “WTApplication” and `Activity.onPause` is executed. This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`&amp;customKey=customValue`

#### Syntax

```
public void onActivityPause(String activityName,
                      Map<String,String> customData)
```

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
WebtrendsDataCollector.getInstance().onActivityPause("Hello World Activity Pause", customData);
```

#### Parameters

- `activityName`: Specifies an activity name associated with the end of user activity.
- `customData` (optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Webtrends Parameter Values

- `dcsuri`: /activity/pause
- `WT.ti`: activityName
- `WT.pi`: activityName
- `WT.sys`: pause
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.

---

## onActivityEnd

The `onActivityEnd` method automatically collects data when an activity stops if the application is extended with “WTApplication” and `Activity.onStop` is executed. This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`&amp;customKey=customValue`

#### Syntax

```
public void onActivityEnd(String activityName,
                      Map<String,String> customData)
```

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
WebtrendsDataCollector.getInstance().onActivityEnd("Hello World Activity End", customData);
```

#### Parameters

- `activityName`: Specifies an activity name associated with the end of user activity.
- `customData` (optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Throws

- `IllegalArgumentException`: Returned when an argument is malformed.

#### Webtrends Parameter Values

- `dcsuri`: /activity/end
- `WT.ti`: activityName
- `WT.pi`: activityName
- `WT.sys`: end
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.

---

## onApplicationError

The `onApplicationError` method collects data when `WTapplication` is passed in an uncaught exception.

This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`&amp;customKey=customValue`

#### Syntax

`Map&lt;String,String&gt; customData)`

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
WebtrendsDataCollector.getInstance().onApplicationError("Hello World Application Error", customData);
```

#### Parameters

- `applicationName`: Specifies an application name associated with application startup, application termination, application foreground, application background, or application error.
- `customData`(optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Throws

- `IllegalArgumentException`: Returned when an argument is malformed.

#### Webtrends Parameter Values

- `dcsuri`: /application/error
- `WT.ti`: applicationName
- `WT.pi`: applicationName
- `WT.sys`: error
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.

---

## onApplicationStart

The `onApplicationStart` method collects data when `Application.onCreate` is executed. This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`a &amp;customKey=customValue`

#### Syntax

```
public void onApplicationStart(String applicationName,
                               Map<String,String> customData)
```

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
try {
        WebtrendsDataCollector.getInstance().onApplicationStart("Hello World Application Start", customData);
} catch (IllegalWebtrendsParameterValueException e) {
        // log error message
        WebtrendsDataCollector.getInstance().getLog().e(e.getMessage());
}
```

#### Parameters

- `applicationName`: Specifies an application name associated with application startup, application termination, application foreground, application background, or application error.
- `customData` (optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Throws

- `IllegalArgumentException`: Returned when an argument is malformed.

#### Webtrends Parameter Values

- `dcsuri`: /application/start
- `WT.ti`: applicationName
- `WT.pi`: applicationName
- `WT.sys`: startup
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.

---

## onApplicationTerminate

The `onApplicationTerminate` method collects data when `Application.onTerminate` is executed. This method can also be called manually, in which case it can accept custom parameters using a Map of key/value pairs. These custom parameters are appended to Webtrends data using the following format:

`a &amp;customKey=customValue`

This method returns a `WTEvent` that indicates the application has terminated. No arguments are required.

#### Syntax

```
public void onApplicationTerminate(String applicationName,
                                     Map<String,String> customData)
```

#### Example

```
// send custom key/value pairs as arguments to event methods (optional)
Map <String, String> customData = new HashMap<String, String>();
customData.put("custom_key", "custom_value");
WebtrendsDataCollector.getInstance().onApplicationTerminate("Hello World Application Terminate", customData);
```

#### Parameters

- `applicationName`: Specifies an application name associated with application startup, application termination, application foreground, application background, or application error.
- `customData` (optional): Specifies a series of custom name-value parameters used to pass data that is not included in the method.

#### Webtrends Parameter Values

- `dcsuri`: /application/terminate
- `WT.ti`: applicationName
- `WT.pi`: applicationName
- `WT.sys`: exit
- `WT.dl`: 61

Additional parameters sent in every event are detailed in the Webtrends Parameters Sent by the Mobile SDK section.
