In android whenever we have to subclass an application object or extend it, in the following way:
public class AndroidApplication extends Application{
....
}
and then make the necessary changes in the manifest file. what is the need to write this line of code?
public class AndroidApplication extends Application{
private static AndroidApplication sInstance;
public static AndroidApplication getInstance() {
return sInstance;
}
....
}
Whenever you are going to access your Application object you are going to access it using the following code:
MyApplication myapp = (MyApplication)getApplicationContext();
The above is always going to return one static object of your Application class. What is the need to write the getinstance method? I have read it on several blogs and on android developer website that the above is the correct way of doing things buy i have never understood why?
The Application object is created in memory when the Application starts running. After this you cannot reinitialize it, meaning you cannot write this code:
MyApplication myapp = new MyApplication();
And even if you did you, the getInstance method would not help.
Thank you in advance.