Skip to content Skip to sidebar Skip to footer

Getapplication Return Which Object Among Applications

in Android there is a base class Application for global application state keeper. I create two or more call extending from Application by getApplication() which object I will get f

Solution 1:

getApplication returns an Application object which will allow you to manage your global application state and respond to some device situations such as onLowMemory() and onConfigurationChanged().

Solution 2:

Application or the Application context is a singleton. Wherever you call it you are getting the same instance of the object. It can be used for many stuff like sharing data between activities.

Way to use app context.

Extend the application class So in your activity you can access the application context and get the bitmap. As the application context is a singleton it will be the same instance in every activity.

MyApplicationappContext= (MyApplication) getApplication();

You also need to add

android:name=".MyApplication"

to application tag in the manifest file.

You cannot extend multiple classes from application as only 1 instance is used and that is the one specified in the manifest file.

Post a Comment for "Getapplication Return Which Object Among Applications"