Wednesday, September 1, 2010

Maintaining global Application state

Maintaining global Application state: "




SDK Version: 

M3






0



As a possible solutions mentioned in previous article Leaving an Android application the Application object can come handy. If you want to store data, global variables that needs to be accessed from everywhere in the application, from multiple Activities, in other words is you want to maintain a global 'state' of the whole application the Application object can help.


For this we must make a class which extends the Android.app.Application class add our own methods to it, and define this class in the AndroidManifest.xml as below:



  1. An example for the Application class:

  2.  

  3. public class HelloApplication extends Application {

  4.         private int globalVariable=1;

  5.  

  6.         public int getGlobalVariable() {

  7.                 return globalVariable;

  8.         }


read more

"

No comments:

Post a Comment