> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/ja/implement-nfc-wallet/make-payment/implement-contactless-payments/3.-consider-application-start.md).

# 3. アプリケーションの起動を考慮する

## 概要

アプリケーションの起動時に、NFC Wallet SDK を初期化します。

デジタルウォレットアプリケーションがサポートする決済体験も設定します:

* サポート **シングルタップ** 決済。
* または次を必須にします **ツータップ** 決済。

たとえ有効にしても **シングルタップ**、一部のトランザクションは次にフォールバックする場合があります **ツータップ**。参照してください [シングルタップはツータップにフォールバックできます](#single-tap-can-fall-back-to-two-tap).

### バックグラウンドの決済アプリケーション

デジタルウォレットアプリケーションがデフォルトの決済アプリケーションである場合（ [既定の決済アプリ](/nfc-wallet-sdk-android/ja/help/knowledge-base/control-nfc-payments-on-android.md#default-payment-application)を参照）、Android はそれをバックグラウンドに保持することがあります。これにより、POS端末からの非接触決済 APDU に対して、 `アプリケーション`.

一部のデバイスでは、デフォルトの決済アプリケーションがバックグラウンドにある間に終了されます。これらのデバイスでは、非接触決済によってアプリケーションのコールドスタートが発生することがあります。詳細は [コールドスタートを最適化する](#optimize-cold-starts).

## SDK 連携

### アプリケーションの起動を更新する

次の `Application.onCreate()`で、アプリケーションは次を行う必要があります:

1. SDK のクイック設定を実行します。
2. 期待される決済体験を設定します:
   * `ONE_TAP_ENABLED` をサポートする **シングルタップ** トランザクション
   * `TWO_TAP_ALWAYS` を設定すると、最初のタップ後に常に認証が必要になります（常に **ツータップ** 決済）
3. SDK を別スレッドで初期化します。
4. 任意: 初期化が成功した後、プレエントリーを有効にします。詳細は [プレエントリーを有効にする](#activate-pre-entry).

手順 1 と 2 については、 [NFC Wallet SDK を初期化する](/nfc-wallet-sdk-android/ja/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md).

{% code title="MyApp.java" expandable="true" %}

```java
public class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        // 値を変更せずにカスタム設定を作成する（最初の SDK 初期化時と同じ設定）
        CustomConfiguration customConfig = new CustomConfiguration.Builder()
                .domesticCurrencyCode(978)
                .keyValidityPeriod(60)
                .build();
        
        // 1 - クイック設定を実行
        // ... SDK に 'Context' があることを確認するため
        try {
            SDKInitializer.INSTANCE.configure(this,  customConfig);
        } catch (InternalComponentException e){
            // SDK 内部コンポーネント例外
            // アプリはこれを無視できます。 
            // そして実際の SDK 初期化 API に進み、例外が発生した場合はそこでエラーハンドリングを行ってください
        } catch (Exception e) {
            // 一般的な例外。これは、アプリケーション起動時にクラッシュにつながる可能性のある 
            // いかなる事象も防ぐための安全策です。 
            // アプリはこれを無視して、実際の SDK 初期化 API に進み、例外が発生した場合はそこでエラーハンドリングを行ってください
        } catch (Throwable e) {
            // この可能性は低いですが、このコードは Application クラス内にあるため、
            // アプリケーション全体に影響する可能性のあるエラーの影響を最小限に抑えるために、 
            // このエラーを捕捉することを推奨します。 
            // このエラーが発生した場合、アプリは SDKInitializer.INSTANCE.initialize() を呼び出してはなりません
        }
    
        // 2 - 決済体験を設定します。
        PaymentExperienceSettings.setPaymentExperience(this, PaymentExperience.ONE_TAP_ENABLED);
        
        // 3 - SDK を初期化します（別スレッドで）
        Thread sdkInit = new Thread(new Runnable() {
            @Override
            public void run() {
                SDKInitializer.INSTANCE.initialize(this, customConfig);
            }
        });
        sdkInit.start();
        
        // 4 - プレエントリーを有効にします（任意）。
        activatePreEntry();
    }
    
    // プレエントリーを有効にします。
    private void activatePreEntry() {
        final DeviceCVMPreEntryReceiver receiver = new DeviceCVMPreEntryReceiver();
        receiver.init();
        final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
        registerReceiver(receiver, filter);
    }
    
    

}
```

{% endcode %}

{% hint style="warning" %}

### シングルタップはツータップにフォールバックできます

有効にすると `ONE_TAP_ENABLED`、すべてのトランザクションが **シングルタップ**.

次のように扱います **シングルタップ** を最良ケースのフローと見なします。必要条件が満たされない場合、NFC Wallet SDK は次にフォールバックします **ツータップ**.

例:

* エンドユーザーがデバイスのロック解除後、設定された有効期間内にタップしません。詳細は `keyValidityPeriod` 次に [NFC Wallet SDK を初期化する](/nfc-wallet-sdk-android/ja/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md).
* 認証なしの LVT トランザクションが設定されたリスクしきい値に達します。その場合、NFC Wallet SDK は認証を要求します。詳細は [リスク管理を定義する](/nfc-wallet-sdk-android/ja/implement-nfc-wallet/make-payment/implement-contactless-payments/7.-configure-cdcvm-experiences/define-risk-management.md).
  {% endhint %}

### コールドスタート時間を短縮する

一部のデバイスでは、デフォルトの決済アプリケーションがバックグラウンドにある間に終了されます。これらのデバイスでは、非接触決済によってアプリケーションの **コールドスタート**.

APDU の処理は、 **コールドスタート**.

コールドスタート処理には次が含まれます:

* サービスのバインディング（約100～200ミリ秒）
* の完了 `Application.onCreate()`

内での処理を最小限にします `Application.onCreate()`。NFC Wallet SDK の設定と初期化だけに限定してください。

の最初の 0.5 秒間は他の処理を避けてください `Application.onCreate()` が始まった後、Android が APDU コマンドを POS 端末に送信する際に、並列処理によって APDU 処理が遅れることがあります。

必要に応じて、SDK 初期化の完了後少なくとも 0.5 秒は、決済以外の処理を遅らせてください。

### プレエントリーを有効にする

プレエントリーを使用して **シングルタップ** 決済。

プレエントリーにより、エンドユーザーは決済フローの開始前に認証できます。

認証は、エンドユーザーが生体認証またはデバイスのキーロック（PIN、パターン、またはパスワード）でデバイスのロックを解除したときに行われます。これにより、追加の確認手順なしで決済を実行できます。

{% hint style="info" %}
このモードが有効な場合、デバイスのロック解除ごとに 1 回の決済のみ許可されます。
{% endhint %}

```java
private void activatePreEntry() {
    DeviceCVMPreEntryReceiver receiver = new DeviceCVMPreEntryReceiver();
    receiver.init();
    IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
    registerReceiver(receiver, filter);
}
```

{% hint style="warning" %}
と併せて追加のインテントフィルターを追加しないでください `DeviceCVMPreEntryReceiver`。このクラスは次に対してのみ動作するよう設計されています `ACTION_USER_PRESENT` インテント。
{% endhint %}


---

# 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.payments.thalescloud.io/nfc-wallet-sdk-android/ja/implement-nfc-wallet/make-payment/implement-contactless-payments/3.-consider-application-start.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.
