This guide here tell you how to create an Application class:
http://www.intridea.com/blog/2011/5/24/how-to-use-application-object-of-android
It mentions that you need to define the name of your Application class in your manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="MyApplication">
I think Application class are useful to hold static variables / objects like for example, GoogleApiClient so that you do not have to reconnect with Google each time your activity ends, instead if you put it in your application class, you will only need to connect once when your app starts up and disconnect when it closes.
I have a multidex app: https://developer.android.com/tools/building/multidex.html
Multidex apps requires me to also give a constant name of "android.support.multidex.MultiDexApplication"
to the application in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
If I have to give android:name="android.support.multidex.MultiDexApplication"
as the application name, I cannot also give android:name="MyApplication"
. As far as I know, an application cannot have two names.
Is it possible to have both multidex and a custom application class in an app?
I think Application class are useful to hold static variables / objects
If they are static
, then Application
is not holding them.
Is it possible to have both multidex and a custom application class in an app?
According to the documentation, you can either have your class extend MultiDexApplication
or have it override attachBaseContext()
and call MultiDex.install(this)
instead of needing MultiDexApplication
.