> For the complete documentation index, see [llms.txt](https://docs.drivequant.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.drivequant.com/challenge/android/get-started.md).

# Get started

## **Prerequisite**

Before starting DriveKit Challenge module integration, make sure that you have [initialized DriveKit](/get-started-drivekit/android.md), especially if you have [disable the SDK auto-initialization](/get-started-drivekit/android/advanced-configurations.md#manually-initialize-the-sdk).&#x20;

{% hint style="danger" %}
If you use DriveKit Challenge without having initialized DriveKit, an exception will be generated and the SDK will not work in your application.
{% endhint %}

## **Integration**

### **Get module from repository**

To add Challenge module to your app, add the following line to your dependencies in your application `build.gradle` file:

```gradle
dependencies {
   implementation 'com.drivequant.drivekit:drivekit-challenge:$drivekit_version'
}
```

{% hint style="info" %}
Replace `$drivekit_version` with the DriveKit version you are using in your app
{% endhint %}

## Initialization

If you have [disabled the SDK auto-initialization](/get-started-drivekit/android/advanced-configurations.md#manually-initialize-the-sdk), an initialization phase is required to use the functions offered by the Challenge component. To initialize Challenge component in your app, you must call the initialization method in `onCreate` method of your application class.

{% tabs %}
{% tab title="DriveKitChallenge" %}

```kotlin
fun initialize()
```

{% endtab %}
{% endtabs %}

## Synchronize list of challenges

To synchronize the list of challenges, call the following method:

{% tabs %}
{% tab title="DriveKitChallenge" %}

```kotlin
fun getChallenges(
   listener: ChallengesQueryListener,
   synchronizationType: SynchronizationType = DEFAULT
)
```

{% endtab %}
{% endtabs %}

[ChallengesSyncStatus](/challenge/android/references-android.md#challengessyncstatus) and [Challenge](/challenge/android/references-android.md#challenge) models are described in the References part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-android/blob/master/ChallengeUI/src/main/java/com/drivequant/drivekit/challenge/ui/challengelist/viewmodel/ChallengeListViewModel.kt#L34) of our DriveKit Demo App to see how it is implemented.
{% endhint %}

## Retrieve local challenge list

You can retrieve the list of challenges stored in the DriveKit local database by calling the previous method but with the `SynchronizationType` parameter to `CACHE`.

## Synchronize challenge detail

You need to call the following method if you want to get more details and statistics about a defined challenge:

{% tabs %}
{% tab title="DriveKitChallenge" %}

```kotlin
fun getChallengeDetail(
    	challengeId: String,
    	listener: ChallengeDetailQueryListener,
    	synchronizationType: SynchronizationType = DEFAULT
)
```

{% endtab %}
{% endtabs %}

This method have the following parameters:

| Field               | Type                | Description                                                                                                                                                                                                                                                              |
| ------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| challengeId         | String              | Unique identifier of the challenge                                                                                                                                                                                                                                       |
| synchronizationType | SynchronizationType | <p>Can be <code>DEFAULT</code> or <code>CACHE</code>.</p><p>- <code>DEFAULT</code> will synchronize the challenge detail by calling the DriveQuant servers</p><p>- <code>CACHE</code> will retrieve the challenge detail already synchronized in the local database.</p> |

[ChallengeDetailSyncStatus](/challenge/android/references-android.md#challengedetailsyncstatus) and [ChallengeDetail](/challenge/android/references-android.md#challengedetail) models are described in the References part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-android/blob/master/ChallengeUI/src/main/java/com/drivequant/drivekit/challenge/ui/challengedetail/viewmodel/ChallengeDetailViewModel.kt#L52) of our DriveKit Demo App to see how it is implemented.
{% endhint %}

## Retrieve local challenge detail data

You can retrieve the details of a given challenge stored in the DriveKit local database by calling the previous method but with the `SynchronizationType` parameter to `CACHE`.

## Join a challenge

To be able to join a given challenge, you can call the following method:

{% tabs %}
{% tab title="First Tab" %}

```kotlin
fun joinChallenge(
    	challengeId: String,
    	listener: JoinChallengeQueryListener
)
```

{% endtab %}
{% endtabs %}

This method have the following parameter:

| Field       | Type   | Description                        |
| ----------- | ------ | ---------------------------------- |
| challengeId | String | Unique identifier of the challenge |

[JoinChallengeSyncStatus](/challenge/android/references-android.md#joinchallengesyncstatus) enum values are described in the References part.

{% hint style="info" %}
Take a look at the [open-source code](https://github.com/DriveQuantPublic/drivekit-ui-android/blob/master/ChallengeUI/src/main/java/com/drivequant/drivekit/challenge/ui/joinchallenge/viewmodel/ChallengeParticipationViewModel.kt#L26) of our DriveKit Demo App to see how it is implemented.
{% endhint %}
