I get the following error when I put my app in the background, or when I press the recent apps button while in the app:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.mappractice.data.LocationItem)
This is the class which generates the error(this is used as an argument for a fragment):
data class LocationItem(
val name: String,
val locations: List<Place>
): Serializable
This is where the argument is used:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.mapView.onCreate(savedInstanceState)
val location = args.location
binding.mapView.getMapAsync(object : OnMapReadyCallback {
override fun onMapReady(googleMap: GoogleMap) {
val boundsBuilder = LatLngBounds.builder()
for (place in location.locations) {
val locationPoz = LatLng(place.lat, place.long)
boundsBuilder.include(locationPoz)
val marker = MarkerOptions()
.position(locationPoz)
.title(place.name)
googleMap.addMarker(marker)
}
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(
boundsBuilder.build(),
800,
800,
0))
}
})
}