Android ArrayList<Location> passing between activities
- by squixy
I have simple class Track, which stores information about route:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import android.location.Location;
public class Track implements Serializable {
private static final long serialVersionUID = -5317697499269650204L;
private Date date;
private String name;
private int time;
private double distance, speed;
private ArrayList<Location> route;
public Track(String name, int time, double distance, ArrayList<Location> route) {
this.date = new Date();
this.name = name;
this.time = time;
this.distance = distance;
this.speed = distance / (time / 3600.);
this.route = route;
}
public String getDate() {
return String.format("Date: %1$td-%1$tb-%1$tY%nTime: %1$tH:%1$tM:%1$tS", date);
}
public String getName() {
return name;
}
public int getTime() {
return time;
}
public double getDistance() {
return distance;
}
public float getSpeed() {
return (float) speed;
}
public ArrayList<Location> getRoute() {
return route;
}
@Override
public String toString() {
return String.format("Name: %s%nDate: %2$td-%2$tb-%2$tY%nTime: %2$tH:%2$tM:%2$tS", name, date);
}
}
And I'm passing it from one activity to another:
Intent showTrackIntent = new Intent(TabSavedActivity.this, ShowTrackActivity.class);
showTrackIntent.putExtra("track", adapter.getItem(position));
startActivity(showTrackIntent);
Where (Track object is element on ListView).
I get error during passing Track object:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = classes.Track)
What is happening?