Application class is the base class where you can maintain global variables.
One can override the Application class by extending his own class and
specifying that class in AndroidManifest.xml’s tag.
Application class exists through out the app life cycle.
Creating a static singletons can serve the purpose instead of extending and overriding Application class.
But if one needs to manage other memory leaks he can override Applications class methods.import android.R.string;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
public class myAppClass extends Application {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
} @Override
public void onCreate() {
super.onCreate();
}
@Override
public void onLowMemory() {
super.onLowMemory();
}
@Override
public void onTerminate() {
super.onTerminate();
}
}
public static String globalWord = “HI DEVS”;
private static myAppClass Singleton;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
} @Override
public void onCreate() {
super.onCreate();
Singleton = this; // create singleton
}
public static myAppClass getSingleton() // access singleton
{
return Singleton;
}
Note: add this class in AndroidManifeist file as below
<application
android:name=”.myAppClass”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”
>
Feedback and comments expexted as usual