Begin by creating a class that extends Android’s android.app.Application. Android creates an instance of this class when the application is started – that is when a DVM process is started to run your apk.
As an example of how the Application works, let’s assume that we are building some type of game. Our game application will have several screens – each screen in this case being an Activity. Players of the game generate points on each screen and their score needs to be tracked across the many screens of our hypothetical game. In order to track the user’s game score across the many Activities that make up the game, we need a place to store the game score for the duration of the game – that is for as long as the application process is running. With a custom Application class created, we can use it to track the game score across the many Activity screens in our game application.
http://www.intertech.com/Blog/androids-application-class/
Instead of this you can use Singletons (Global Variables), same functionality in a more modular way.
No comments:
Post a Comment