Android版的ArrayList<地点>活动之间传递 [英] Android ArrayList<Location> passing between activities

查看:147
本文介绍了Android版的ArrayList<地点>活动之间传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的类曲目,其中储存的路由信息​​:

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);

在哪里(跟踪对象是ListView的元素)。
我通过跟踪对象时出现错误:

Where (Track object is element on ListView). I get error during passing Track object:

了java.lang.RuntimeException:Parcelable遇到IOException异常写入序列化对象(名称= classes.Track)

这是怎么回事?

推荐答案

我认为问题是,位置不是序列化。有很多来自谁拥有试图序列化位置对象的问题人们对SE的问题。然而,位置 Parcelable ,所以也许你会有更好的运气只是实施 Parcelable 为您的类,而不是使用序列化

I think the problem is that Location is not serializable. There are a lot of questions on SE from people who have problems trying to serialize Location objects. However, Location is Parcelable, so maybe you would have better luck just implementing Parcelable for your class instead of using Serializable

这篇关于Android版的ArrayList&LT;地点&gt;活动之间传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆