Wednesday, 3 July 2013

Global object / variable in Andoird Application

When we need to define global variables or global object in Android, we can extend the base class. Here are the details step: (1) Define a class extending the class
public   class   GlobalAccess  extends  Application {  
    private  Boolean notification= false ;  
    public  Boolean getNotification() {  
        return  notification;  
    public  void  setNotification(Boolean notification) {  
        this.notification = notification;  
(2) Add to AndroidManifest.xml
< application  
android:name = ".GlobalAccess"  
        ....  /> 
(3) Now, we can use Context.getApplicationContext() method to get this Global object / variable.
GlobalAccess global;  
public  void  onCreate(Bundle savedInstanceState) {  
    Boolean notification=global.getNotification();


Post a Comment