Explicit Intent (Parceable)


Fri Apr 15 2022 04:48:01 GMT+0000 (UTC)

Saved by @anasrathore #kotlin

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    ... ... ...
    // Add for using latest experimental build of Android Extensions
    androidExtensions {
        experimental = true
//parceable class
data class Category(
    var categoryId: Int,
    var categoryName: String
) : Parcelable
--next class--
data class Item(
    var imageId: Int,
    var title: String,
    var price: Double,
    var category: Category
) : Parcelable
val intent = Intent(this, AnotherActivity::class.java)
item.title = "Anas Rathore"
item.price = 50303
intent.putExtra("extra_item", item.title)
intent.putExtra("item_price", item.price)<- key and object
val item = intent.getParcelableExtra("extra_item")
val item = intent.getParceableExtra("item_price")
// Do something with the item (example: set Item title and price)

--if object is pre-defined, data is pre-defined or hard coded--
val student <- object = Student() <- class