> For the complete documentation index, see [llms.txt](https://docs.digitalturbine.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalturbine.com/dt-ignite/sdk-reference/connect-to-ignite.md).

# Connect to Ignite

When connecting to Ignite, ensure the Host App is in the foreground, active, and visible to the user. DT sends callbacks on the thread that the initialization was executed on.

There are no restrictions on the lifecycle owners for the connection: Activity, Fragment, Service, ViewModel, etc. However, do not connect to Ignite from classes or methods that might be called while the Host App is in the background, such as the Application class or broadcast receivers. Connecting in this manner causes multiple unnecessary connection attempts, potential resource conflicts, and unexpected behaviors when receiving broadcasts in the background.

Authentication occurs internally as part of the connection process. The SDK sends the `onConnected()` callback only after the connection is established and authentication succeeds. You can safely begin calling API methods after receiving `onConnected()`.

{% hint style="info" %}
Initialization failure indicates that Ignite is not present on the device.
{% endhint %}

To connect to Ignite via the SDK:

1. Declare and create an instance of `IIgniteService`:

{% code title="Kotlin" %}

```kotlin
lateinit var igniteService: IIgniteService
// ...

// After SDK is initialised the IgniteService instance is returned.
// It can also be retrieved later using IgniteServiceSdk.instance()
// NOTE: `clientSecret` can be empty for initial integration
igniteService = IgniteServiceSdk.init(context, clientSecret)
```

{% endcode %}

2. Call the `connect()` method:

{% code title="Kotlin" %}

```kotlin
IgniteServiceSdk.instance().connect(object: IConnectionCallback {
     override fun onConnected() {
          // Connection with Ignite is established
          Toast.makeText(applicationContext, "Connected.", Toast.LENGTH_SHORT).show()
     }

     override fun onDisconnected(message: String?) {
          Toast.makeText(applicationContext, "Disconnected from Ignite Service: $message", Toast.LENGTH_SHORT).show()
     }
})

// or

igniteService.connect(this)
```

{% endcode %}

## Example <a href="#h_01k25vm0hnkr5vc01zx9jfshy6" id="h_01k25vm0hnkr5vc01zx9jfshy6"></a>

{% code title="Kotlin" %}

```kotlin
class ExampleActivity: AppCompatActivity(), IConnectionCallback {
    private lateinit var igniteService: IIgniteService

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        igniteService = IgniteServiceSdk.init(this, clientSecret = "")
        igniteService.connect(this)
    }

    override fun onConnected() {
        Log.i(TAG, "Connected to Ignite Service")
    }

    override fun onDisconnected(message: String?) {
        Log.i(TAG, "Disconnected from Ignite Service: $message")
    }

    override fun onDestroy() {
        super.onDestroy()
        igniteService.disconnect(this)
    }

    companion object {
        const val TAG = "SDK"
    }
}
```

{% endcode %}

## Troubleshooting Connections <a href="#h_01k25vm0hpxf1y0hf9yr5c6fst" id="h_01k25vm0hpxf1y0hf9yr5c6fst"></a>

If your Host App is unable to connect to Ignite, you may receive one of the following error messages:

| ERROR MESSAGE                                    | DESCRIPTION                                                                                          |
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
| Connection failed to unknown reason              | Ignite is not present in the device.                                                                 |
| Authentication Exception: Can not create session | `Client ID`, `Client Secret`, or package name does not match what was given for DT Configuration.    |
| Authentication Exception Code -2                 | Host App signing certificate fingerprint does not match with what was provided for DT Configuration. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digitalturbine.com/dt-ignite/sdk-reference/connect-to-ignite.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
