> For the complete documentation index, see [llms.txt](https://app.developers.karte.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://app.developers.karte.io/android-sdk-appendix/appendix-logout-android-sdk.md).

# \[Android]アプリケーションのログアウトに対応する

ログイン/ログアウト機能のあるアプリケーションでは、ログイン時に `identify` イベントで `user_id` を送信しユーザーをメンバー化します。\
このときSDKが自動生成する `visitor_id` と明示的に送信した `user_id` は紐付いた状態となります。

アプリケーション側でユーザーがログアウトを行った場合でもこの状態は維持されるため、アプリケーション上の状態と、KARTE側の状態が一致しない状態になってしまいます（アプリケーション側はビジター扱い、KARTE側はメンバー扱い）

**この状態を避けるために、ビジターIDを再生成する機能を利用することが可能です。**

## ビジターIDの再生成の方法

* ログアウト時に`renewVisitorId()`を実行することで再生成されます

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

```kotlin
KarteApp.renewVisitorId()
```

{% endcode %}
{% endtab %}

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

```java
KarteApp.renewVisitorId();
```

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

## ビジターIDの再生成機能時に行われる処理

以下の処理が行われます。

* リセット対象のvisitorのプッシュ通知の購読フラグ（plugin\_native\_app\_identity.subscribe）を `非購読（false）` に変更
* 端末に保存されている設定値の削除
* visitor\_id の再発行
* 新たに生成された visitor に対してFCMトークンを紐付け
  * 新たに生成されたvisitorでplugin\_native\_app\_identify.subscribeを再送信
* アプリビジターIDの再生成（native\_app\_renew\_visitor\_id）イベントを送信

## WebView利用時の注意事項

[WebView連携](/android-sdk/webview-android-sdk.md) を行っている場合は、ビジターIDの再生成と合わせ、WebView上のCookie/localStorageについても削除が必要です。

削除が適切に行われない場合、ログアウト前の状態が意図せず継続する可能性があります。


---

# 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://app.developers.karte.io/android-sdk-appendix/appendix-logout-android-sdk.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.
