Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android Studio 添加 Parcelable 序列化插件提效

編輯:關於 Android 開發

Parcelable 與 Serializable

Android 中物件傳遞可實作 Serializable 或 Parcelable。Parcelable 效率較高,適合 Intent 與 IPC。

設定

安裝插件

進入 Settings,開啟 Plugins,搜尋 Parcelable,安裝 Android Parcelable code generator,完成後重啟 Android Studio。

Plugins搜尋 Parcelable安裝

使用方式

在實體類別上按下滑鼠右鍵,選擇 Generate,再點選 Parcelable,即可自動產生序列化程式碼。

GenerateParcelable選擇屬性

注意事項

若物件中包含其他物件屬性,該屬性也必須實作 Parcelable,否則會序列化失敗。

物件屬性錯誤提示

傳遞時使用 Bundle.putParcelable,接收時使用 getParcelableExtra。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved