Create a class by extending `Application` and override its `onCreate()` to initialize Amplify in your application.
Right-click on your namespace (e.g. `com.example.MyAmplifyApp`), click **New**, and click **Java Class** or **Kotlin File/Class** depending on which language you choose.
Configure the new class in **New Java Class**:
- Enter *MyAmplifyApp* in the **Name** field
- Press enter
- Extend *MyAmplifyApp* from *android.app.Application* by adding `extends Application` to your class
Initialize Amplify by adding an `onCreate` method with the following code:
```java
public void onCreate() {
super.onCreate();
try {
Amplify.configure(getApplicationContext());
Log.i("MyAmplifyApp", "Initialized Amplify");
} catch (AmplifyException error) {
Log.e("MyAmplifyApp", "Could not initialize Amplify", error);
}
}
```
Configure the new class in **New Kotlin File/Class**:
- Enter *MyAmplifyApp* in the **Name** field
- Press enter
- Extend *MyAmplifyApp* from *android.app.Application* by adding `: Application()` to your class
Initialize Amplify by adding an `onCreate` method with the following code:
```kotlin
override fun onCreate() {
super.onCreate()
try {
Amplify.configure(applicationContext)
Log.i("MyAmplifyApp", "Initialized Amplify")
} catch (error: AmplifyException) {
Log.e("MyAmplifyApp", "Could not initialize Amplify", error)
}
}
```
This overrides the `onCreate()` to initialize Amplify when your application is launched.
Next, configure your application to use your new custom `Application` class. Open **manifests** > **AndroidManifest.xml**, and add a `android:name` attribute with the value of your new class name:
```xml
```
Next, build and run the application. In logcat, you'll see a log line indicating success:
```console
com.example.MyAmplifyApp I/MyAmplifyApp: Initialized Amplify
```