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 ...

Get Mastering Android Development with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.