# Bug Reporting Callbacks

{% hint style="warning" %}

#### Avoiding Memory Leaks

These APIs hold the callbacks in a strong reference, so we strongly suggest to avoid registering callbacks without unregistering them when needed, as it may cause a memory leak.
{% endhint %}

### Before Invoking Luciq

This block is executed on the UI thread. You can use it to perform any UI changes before the SDK's UI is shown.

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
BugReporting.setOnInvokeCallback {
					 //do something
 }
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
BugReporting.setOnInvokeCallback(new OnInvokeCallback() {
            @Override
            public void onInvoke() {
               //do something
            }
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Before Sending a Report

This block is executed in the background before sending each report. You can use it to attach logs and extra data to reports. You can also use this API to run some logic after the bug is reported and before it gets synced with the backend, in case you need to access some data to take specific actions.

**Available Data**: tags, consoleLog, filesAttachments, userAttributes, userData, appending data to consoleLog, attaching files, and adding tags.

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
Luciq.onReportSubmitHandler{report -> }
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
Luciq.onReportSubmitHandler(new Report.OnReportCreatedListener() {
            @Override
            public void onReportCreated(Report report) {
                
            }
        });
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
By writing `report.` in the callback, the IDE autocomplete feature will show all of the mentioned operations that you can do or access on the report automatically.
{% endhint %}

### After Dismissing Luciq

This block is executed on the UI thread. You can use it to perform any UI changes after the SDK's UI has been dismissed.

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
BugReporting.setOnDismissCallback { issueState, reportType -> }
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
BugReporting.setOnDismissCallback(new OnSdkDismissCallback() {
            @Override
            public void call(DismissType issueState, OnSdkDismissCallback.ReportType reportType) {
                
            }
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

You can find the following parameters within the `setOnDismissCallback` callback.

#### `DismissType`

Returns how the SDK was dismissed. It can be set to one of the three following possibilities:

* `SUBMIT`: Indicates that the issue was submitted and will be uploaded
* `CANCEL`: Indicates that the user closed the Luciq view without report submission
* `ADD_ATTACHMENT`: Indicates that the issue is in the process of being reported (for example, user is taking another screenshot)

#### `ReportType`

The type of report that was sent. If the SDK was dismissed without selecting a report type, it will be set to `bug`, so you might need to check `issueState` before `ReportType`. The possible different types are `bug`, `feedback`, `question`, and `other`.

## Disabling Callbacks

To disable any previously created callbacks, you'll simply need to set the method to `null` as shown below:

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
BugReporting.setOnInvokeCallback(null)
Luciq.onReportSubmitHandler(null)
BugReporting.setOnDismissCallback(null)
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
BugReporting.setOnInvokeCallback(null);
Luciq.onReportSubmitHandler(null);
BugReporting.setOnDismissCallback(null);
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://docs.luciq.ai/android/set-up-luciq-for-android/set-up-bug-reporting/bug-reporting-callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
