//dependencies
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
@Parcelize
data class Category(
var categoryId: Int,
var categoryName: String
) : Parcelable
--next class--
@Parcelize
data class Item(
var imageId: Int,
var title: String,
var price: Double,
var category: Category
) : Parcelable
--passing--
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
--retreving--
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
Comments