Understanding Android Context
All our main screens now have their layouts defined. We will now explain Android Context since each screen we just created represents one Context
instance. If you go through the class definition and follow class extension, you will realize that each activity we create extends the Context
class.
Context
represents the current state of the application or object. It is used to access specific classes and resources of the application. For example, consider the following lines of code:
resources.getDimension(R.dimen.header_height) getString(R.string.app_name)
Access we showed is provided by the Context
class, which shows our activities are extending. Context
is needed when we have to launch another activity, start a service, or send broadcast messages. We will show use of these methods when the time is proper. We already mentioned that each screen (Activity
) of an Android application represents a Context
instance. Activities are not the only classes that represent...