我有一个类别,并且我点击了附加类别。 这在6个屏幕上都有效,但在最后一个屏幕上我收到了空值
我把多余的东西投入的活动
adapter.setOnItemClickListener { item, view ->
val categories = item as Categories
val intent = Intent(view.context, LearningFirstLibras::class.java)
intent.putExtra(CATEGORY_KEY, categories.category)
startActivity(intent)
}
类别
@Parcelize
class Category(
val name: String,
val imageURL: String,
val real_name: String,
val object_1_screen_libras_image: String,
val object_1_screen_libras_text: String,
val object_2_screen_libras_text: String,
val object_2_screen_libras_image: String,
val object_3_screen_libras_text: String,
val object_3_screen_libras_image: String,
val object_1_screen_asl_text: String,
val object_1_screen_asl_image: String,
val object_2_screen_asl_text: String,
val object_2_screen_asl_image: String,
val object_3_screen_asl_text: String,
val object_3_screen_asl_image: String,
val question: String,
val answer: String,
val alternative_1: String,
val alternative_2: String,
val alternative_3: String,
val alternative_4: String
) : Parcelable {
constructor() : this("", "", "", "", "",
"","","","",
"","","","",
"","","","","","",
"","")
}
我为空的活动
class Quiz : AppCompatActivity() {
var categoryF:Category = Category()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_quiz)
categoryF = intent.getParcelableExtra(NewWordsActivity.CATEGORY_KEY)
答案 0 :(得分:0)
尝试
使用捆绑包发送可包裹包裹
val intent = Intent(this, ProfilePage::class.java)
var bundle = Bundle()
bundle.putParcelable(CATEGORY_KEY, categories.category)
intent.putExtra("myBundle",bundle)
startActivity(intent)
恢复可打包邮件
val bundle = intent.getBundleExtra("myBundle")
var categoryF = bundle.getParcelable<Category>(NewWordsActivity.CATEGORY_KEY) as Category