作者amhuang (阿銘)
看板AndroidDev
標題[問題]在onSaveInstanceState(), Bundle HashMap
時間Wed Feb 19 12:56:22 2014
想請問Bundle HashMap 發生了錯誤, Logcat 的訊息是
android.os.BadParcelableException:
ClassNotFoundException when unmarshalling: com.myapp.model.StationHashMap
unmarshalling 時找不到Class = ="
在 com.myapp.model.StationHashMap 有implements Parcelable
而HashMap value 的類別是自訂的類別為Station
程式碼:
MapFragment.java:
https://gist.github.com/ymhuang0808/9086234
片段程式, 是onSaveInstanceState() 的部分, 主要是將mStationMap set到
stationHashMap 中再put 到bundle
以下都是資料儲存的model 類別都有實做Parcelable
StationHashMap.java :
https://gist.github.com/ymhuang0808/9086124
Station.java :
https://gist.github.com/ymhuang0808/9086148
會寫成StationHashMap 是參考StackOverflow 的這篇
http://goo.gl/ZSBlrL
他說Parcelable 比Serializable 快, 也看到有人測試的文章
http://goo.gl/Is0eg8
嘗試過的有加入bundle.setClassLoader(getClass().getClassLoader())
指定ClassLoader
還是沒work...
如果有經驗的大大可以提供一下解決方式,或者提醒能解決的方向
感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.168.239.157
※ 編輯: amhuang 來自: 1.168.239.157 (02/19 12:57)
※ 編輯: amhuang 來自: 1.168.239.157 (02/19 12:57)
1F:→ laiair:會不會是class沒有在manifest註冊啊 02/19 19:54
2F:→ amhuang:我從Service bundle 過來就可以... 在SupportMapFragment 02/19 21:30
3F:→ amhuang:就會不行... 02/19 21:30
4F:→ amhuang:是Service bundle 到Activity 02/19 21:32
5F:→ amhuang:只好利用Activity 存了... 然後有restore再call fragment 02/19 22:15