Click to Open Details
Explore how to implement item click handling in a travel blog app using Kotlin. Understand passing data between activities with the Parcelable interface and intent bundles to efficiently open detailed views. Learn to enhance user experience with visual feedback on item selection.
We'll cover the following...
Details screen changes
The very first thing we need to do is update the details screen. Instead of loading blog details again, we can just pass the data from the MainActivity to the BlogDetailsActivity via the intent bundle.
First let’s add a companion object with an EXTRAS_BLOG constant. In Kotlin a companion object is used to declare constants in the class or functions which don’t require instances of the object.
To learn more about delegate properties navigate to Kotlin documentation.
Next, let’s remove the loadData method and instead, call the showData method. To get Blog from the parameter we need to:
-
Acquire a reference to the Intent object via the
intentproperty (object which was used to launch this Activity) ...