kotlin 简单实现实体类的Parcelable序列化接口

以前用Java代码实现Parcelable序列化接口,需要在实体类里面写一堆代码,麻烦得很,现在用kotlin开发安卓APP,只需2步就可以实现,这里记录下;

  1. 在模块的build.gradle文件如下配置:
Kotlin 复制代码
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

2.在是实体类中使用注解@Parcelize,并实现接口Parcelable

Kotlin 复制代码
@Parcelize
class Person(val name: String, val age: Int) : Parcelable

是不是比Java时代简单多了,好了,又可以愉快玩耍了。

相关推荐
恋猫de小郭6 小时前
Dart Skills CLI 1.0 :AI 时代的 Dart 交付支持
android·前端·flutter
2501_916007476 小时前
使用Apple Dashboards显示和自定iOS应用性能指标与数据可视化指南
android·ios·小程序·https·uni-app·iphone·webview
leluckys6 小时前
【KMP】-KMP 项目commonMain、androidMain、iosMain 到底放什么?
kotlin
蜡台7 小时前
# 已解决|MySQL 8\.4\.11 密码正确仍报错1045 \(28000\) Access denied 终极修复方案
android·mysql·adb
JMchen1237 小时前
2026年六款主流AI编程工具深度实测:Cursor、Copilot、Claude Code等对比与选型思考
android·kotlin·copilot·ai编程·开发工具·cursor·claude code
mmsx7 小时前
osmdroid 地图实战 05|让地图动起来:三个实时能力 + 六条工程排雷清单
android
码农coding7 小时前
android12 SystemUI组件之StatusBar启动
android
hai_android8 小时前
Kotlin 协程上下文:从 plus 到 CombinedContext,彻底搞懂左偏结构
android·kotlin
淡淡的香烟8 小时前
AndroidKMP之网络请求
android·网络
basketball6168 小时前
AI Infra 推理部署技术总结:2. vLLM 内核——PagedAttention 与调度器原理
android·人工智能·vllm·ai infra