【发布时间】:2017-05-05 11:35:34
【问题描述】:
有问题的 Android 项目已经使用 Serializable 在内部模块之间传递信息。
我正在开发其中一个模块,它也使用外部库来计算导航路线。
我需要将这些“外部”对象之一传递给另一个模块,这不是可序列化的,因此我无法正常发送它。我之前的程序员已经将所有不可序列化的对象转换为包装类中的静态变量,我不确定这是否是一个好主意,即使模块应该一直保持活动状态。
这是 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;
}
将道路写成瞬态会使我丢失数据,为道路编写一个完整的包装类将是太多的工作(它需要构建叠加层,所以很多几何图形都在内部并且来自外部库,所以我可能会忘记某物)。将整个项目改为 Parcelable 也不现实。
有什么解决办法吗?将我需要的内容保存为静态的最佳方式真的是?
【问题讨论】:
标签: java android parcelable serializable