Thursday, 18 August 2011

Android Application Global class

Hi in this blog i am going to write about the application global class.
You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag.
Below is the code tutorial of application global class:
Step1:) Create a new class which extends the application class as follows:

public class ApplicationSetterClass extends Application{
    private String mname;
    private String mage;
    // This Method will get the name  saved in application class
    public String getName()
        return mname;

    // This Method will set the name in application class
    public void setName(String mname)

    // This Method will get the age  saved in application class
    public String getAge()
        return mage;

    public void setAge(String mage)

Step2):Now  declare your application gobal class in application tag in android  manifest file as follows:

<application android:icon="@drawable/icon" android:name="ApplicationSetterClass" android:label="@string/app_name">

Step3)Now your applciation global class is ready to save the application state:Make a object of the ApplicationSetterClass in your activty where you want to use it as follows:

ApplicationSetterClass  appset=(ApplicationSetterClass) getApplication(); 

Now you can save any data as follows:

 appset.setName("Your droid tutorial");

And now this data will be available  globally to whole application:
You can retrieve data as follows:


Source code:

1 comment:

iOS Tutorial on Enumeration  So as we are talking about enumeration in iOS,the first thing comes into mind are Collections such as Array...