有問題的Android項目已經使用Serializable在內部模塊之間傳遞信息。發送可串行化的可分區對象
我正在使用外部庫計算導航路線的那些模塊之一。
我需要將其中一個「外部」對象傳遞給另一個模塊,這不是可序列化的,所以我無法正常發送它。我之前的程序員已經將所有不可序列化的對象轉換爲包裝類中的靜態變量,但我不確定這是否是一個好主意,即使模塊應始終保持活動狀態。
這是序列化包裝類:
private static Road road;
private NavigationStep firstNavigationStep;
/**
* To send the route information to the App. Here is everything the app needs to display the
* data to the user.
* @param road the route the user is to follow
* @param firstNavigationStep the users location and the current Step.
*/
public CurrentRoad(Road road, NavigationStep firstNavigationStep){
this.firstNavigationStep = firstNavigationStep;
this.road = road;
}
編寫路爲瞬時讓我失去數據,寫入道路整體包裝類將太多的工作(這是需要建立覆蓋,所以很多Geometry都在裏面,來自外部庫,所以我可能會忘記一些東西)。將整個Project改爲Parcelable也是不現實的。
有沒有解決方法?最好的方法是將我需要的東西保存爲靜態的嗎?
我們的架構中已經有一個消息服務,它使用了Serializable。它是項目中其他人編寫的MessageManger。 我在團隊中有點新鮮,項目跨越多個公司,因此添加外部庫不是那麼簡單 – Raeglan