I have an arraylist of type Book. How can I pass the array list to another activity and read from that list in the other activity? Here's what I have so far.
txtViewAll.setOnClickListener {
Intent(context, BookActivity::class.java).apply {
putExtra("list", list[layoutPosition].list)
context.startActivity(this)
}
}
// to read
val bookList = intent.getStringArrayListExtra("list") as ArrayList<Book>
for (book in bookList) {
list.add(Book(book.id, book.title, book.image, book.subtitle, null, null, 0, 0));
}
Here's each Book
data class Book(val id: String, val title: String, var image: String, var subtitle: String, var author: String?, var desc: String?, var uploadDate: Long, var starCount: Long)