The Android platform offers a spell checker framework that lets you
implement and access spell checking in your app. The framework is one of the
Text Service APIs.

To use the framework in your app, you create an Android service that
generates a spell checker *session* object. Based on text you provide,
the session object returns spelling suggestions generated by the spell
checker.

## Spell checker lifecycle

The following diagram shows the lifecycle of the spell checker service:
![An image showing the lifecycle for the spelling checker service](https://developer.android.com/static/resources/articles/images/spellcheck_lifecycle.png) **Figure 1.** The spell checker service lifecycle.

To initiate spell checking, your app starts its implementation of the spell
checker service. Clients in your app, such as activities or individual UI
elements, request a spell checker session from the service, then use the session
to get suggestions for text. As a client terminates its operation, it closes
its spell checker session. If necessary, your app can shut down the spell
checker service at any time.

## Implement a spell checker service

To use the spell checker framework in your app, add a spell checker service
component that includes the session object definition. You can also add an
optional activity to your app that controls settings. Add an XML metadata file
that describes the spell checker service, and add the appropriate elements to
your manifest file.

### Spell checker classes

Define the service and session object with the following classes:

| **Note:** Implement all aspects of spell checking asynchronously and in a thread-safe manner. A spell checker might be called simultaneously by different threads running on different cores. The `SpellCheckerService` and `SpellCheckerService.Session` take care of this automatically.

### Spell checker manifest and metadata

In addition to code, provide the appropriate manifest file and a metadata
file for the spell checker.

The manifest file defines the app, the service, and the activity for
controlling settings, as shown in the following example:  

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.samplespellcheckerservice" >
    <application
        android:label="@string/app_name" >
        <service
            android:label="@string/app_name"
            android:name=".SampleSpellCheckerService"
            android:permission="android.permission.BIND_TEXT_SERVICE" >
            <intent-filter >
                <action android:name="android.service.textservice.SpellCheckerService" />
            </intent-filter>

            <meta-data
                android:name="android.view.textservice.scs"
                android:resource="@xml/spellchecker" />
        </service>

        <activity
            android:label="@string/sample_settings"
            android:name="SpellCheckerSettingsActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>
</manifest>
```

Components that want to use the service must request the permission
[BIND_TEXT_SERVICE](https://developer.android.com/reference/android/Manifest.permission#BIND_TEXT_SERVICE)
to ensure that only the system binds to the service. The service's definition
also specifies the `spellchecker.xml` metadata file, which is
described in the next section.

The metadata file `spellchecker.xml` contains the following
XML:  

```xml
<spell-checker xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/spellchecker_name"
        android:settingsActivity="com.example.SpellCheckerSettingsActivity">
    <subtype
            android:label="@string/subtype_generic"
            android:subtypeLocale="en”
    />
    <subtype
            android:label="@string/subtype_generic"
            android:subtypeLocale="fr”
    />
</spell-checker>
```

The metadata specifies the activity that the spell checker uses to control
settings. It also defines subtypes for the spell checker. In this case, the
subtypes define locales that the spell checker can handle.

## Access the spell checker service from a client

apps that use
[TextView](https://developer.android.com/reference/android/widget/TextView) and
[EditText](https://developer.android.com/reference/android/widget/EditText)
views automatically benefit from spell checking, because `TextView`
automatically uses a spell checker:
![An image showing how the spell checker is automatically enabled in EditText](https://developer.android.com/static/images/ui/spellchecker_edittext.png) **Figure 2.** Spell checking in an `EditText`.

However, you might want to interact directly with a spell checker service in
other cases. The following diagram shows the flow of control for interacting
with a spell checker service:
![An image showing the diagram of the interaction with a spell checker service](https://developer.android.com/static/resources/articles/images/spellcheck_client_flow.png) **Figure 3.** Interaction with a spell checker service.

The
[LatinIME
input method editor in the Android Open Source Project](https://android.googlesource.com/platform/packages/inputmethods/LatinIME/) contains an example of
spell checking.