Android context

We all know how much of a key role context plays in Android. All Android components have context and they are capable of doing different things. Every time you need to access activity's context to pass it while displaying toast, dialogs, creating intent, and so on, we used to use SomeActivity.this. Kotlin will not allow this, but we have a slightly different way of doing this. We wanted to create TweetView and it was expecting context as a parameter. We can simply pass context like such this, observe this@TweetDetailActivity, which is nothing but TweetDetailActivity.this:

    llTweets.addView(TweetView(this@TweetDetailActivity, result.data))

Get Kotlin Blueprints 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.