Wednesday, 26 June 2013

How to declare a Global variable in Android.

When we need to have several variables across application we can go for global variable. Here I am going to explain, defining global variable by extending the Android's Application class. This is the base class for maintaining global application state.

1) Create a class that extends Application class.
    public  class  Global extends Application {
                                private Boolean _notification=false;
                                public Boolean get_notification() {
                                return _notification;
                                public void set_notification(Boolean _notification) {
                                 this._notification = _notification;

2)Add the class to the AndroidManifest file as an attribute of <application> tag:
                                .... />
Android will automatically create an instance of that class and make it available for your entire application.
3) You can access it from any context using the Context.getApplicationContext() method. Now    we can access the global data across the application .like
                                 Global global;
                                public void onCreate(Bundle savedInstanceState) {
                                Boolean notification=global.get_notification();}


  1. This is the base class for maintaining Moviles android baratos global application state.
    1) Create a class that extends Application clas

    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. classic article. Really helpful.


  3. Thank you so much for this wonderful and helpful article.

    kind regards,
    SANI HYNE (delickate)

  4. Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
    Android Online Training

  5. I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog. Selenium Training in Chennai | Salesforce Training in Chennai


  6. It was so good to read and useful to improve my knowledge as updated one.Thanks to Sharing.
    ETL Testing Online Training
    Hadoop online Training
    Informatica Online Training

  7. You've made some good points there. I looked on the internet for more information about this
    Mainframe Training In Chennai | Hadoop Training In Chennai | ETL Testing Training In Chennai

  8. The information which you have provided is very good. It is very useful who is looking for selenium Online Course Bangalore

  9. nice , Here i found the example in kotlin