【问题标题】:pass array using intent使用意图传递数组
【发布时间】:2016-03-13 18:47:51
【问题描述】:

在我的Activity A中,我想将results 传递给Activity B

ArrayList<SearchResults> results = new ArrayList<SearchResults>();

 i.putExtra("resuls", results);

活动 B

 results=getIntent().getExtras().getString("results");

应用程序在想要意图B

时崩溃
 Process: com.example.project.myapplication, PID: 3162
    java.lang.RuntimeException: Parcel: unable to marshal value com.example.project.myapplication.bean.SearchResults@f8e8031
            at android.os.Parcel.writeValue(Parcel.java:1397)
            at android.os.Parcel.writeList(Parcel.java:738)

搜索结果

public class SearchResults {

    private String weather = "";
    private String date = "";
    private String status = "";
    private String timeIn="";
    private String timeOut="";
    private String project="";
    private String description="";
    private String progress="";

    public void setWeather(String weather) {
        this.weather = weather;
    }

    public String getWeather() {
        return weather;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDate() {
        return date;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public void setTimeIn(String timeIn) {
        this.timeIn = timeIn;
    }

    public String getTimeIn() {
        return timeIn;
    }

    public void setTimeOut(String timeOut){
       this.timeOut=timeOut;
    }

    public String getTimeOut()
    {
        return timeOut;
    }

    public void setProject(String project){
        this.project=project;
    }

    public String getProject()
    {
        return project;
    }

    public void setProgress(String progress){
        this.progress=progress;
    }

    public String getProgress()
    {
        return progress;
    }

    public void setDescription(String description){
        this.description=description;
    }

    public String getDescription()
    {
        return description;
    }



}

如何传递数组并最终在活动 B 中显示它们?谢谢

【问题讨论】:

    标签: android arrays android-intent


    【解决方案1】:

    第 1 步:让 SearchResults 实现 ParcelableSerializable

    第 2 步:使用 getParcelableArrayList()getSerializable() 代替 getString() 从附加值 Bundle 中检索值。

    【讨论】:

    • 如果我不想取出值,只传递,我应该使用哪种方式?
    • @Seng:如果你不想取回值,就不要一开始就发送值。
    • 使用可序列化来传递 bean 对象,并使您的 bean 类实现可序列化
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多