# Initialization

This is how to initialize the Wepin Android Login Library.

<pre class="language-kotlin"><code class="lang-kotlin"><strong>import com.wepin.android.loginlib.WepinLogin;
</strong></code></pre>

Before creating a WepinLogin instance, please pass the app's Activity Context, App ID, and App Key to the WepinLoginOptions object as follows.

```kotlin
WepinLoginOptions wepinLoginOptions = new WepinLoginOptions(this, appId, appKey);
```

Please create the WepinLogin instance by passing the previously created WepinLoginOptions.

```kotlin
WepinLogin wepinLogin = new WepinLogin(wepinLoginOptions);
```

After creating the WepinLogin instance, call the `init` method to proceed with the initialization.

```kotlin
wepinLogin.init()
```

### Example

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

```java
public class MainActivity extends ComponentActivity {
  private WepinLogin wepinLogin;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_example_main);

      String appId = getResources().getString(R.string.wepin_app_id);
      String appKey = getResources().getString(R.string.wepin_app_key);

      WepinLoginOptions wepinLoginOptions = new WepinLoginOptions(this, appId, appKey);
      wepinLogin = new WepinLogin(wepinLoginOptions);

      // Call initialize function
      CompletableFuture<Boolean> res = wepinLogin.init();
      res.whenComplete((infResponse, error) -> {
          if (error == null) {
              System.out.println("infResponse: " + infResponse);
          } else {
              // render error UI
          }
      });
  }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class MainActivity : ComponentActivity() {
    private lateinit var wepinLogin: WepinLogin
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_example_main)

        val wepinLoginOptions =  WepinLoginOptions(
            context = this,
            appId=resources.getString(R.string.wepin_app_id),
            appKey = resources.getString(R.string.wepin_app_key)
        )
        wepinLogin = WepinLogin(wepinLoginOptions)
        // Call initialize function 
        val res: CompletableFuture<Void> = wepinLogin.init()
        res.whenComplete { infResponse, error ->
            if (error == null) {
                println("infResponse: $infResponse")
            } else {
                // render error UI
            }
    }
    // ...
}
```

{% endtab %}
{% endtabs %}

## isInitialized

You can use the `isInitialized` method to check whether the WepinLogin instance has been initialized correctly. The return values are as follows:

* *boolean*\
  it returns **true** if the initialization is successful and **false** if the initialization fails.

```java
if(wepinLogin.isInitialized()) {
    // Success to initialize WepinLogin
}
```


---

# 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.wepin.io/en/widget-integration/android-java-and-kotlin-sdk/login-library/init.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.
