在我的活动A 中,我想将results
传递给活动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中显示它们?感谢
答案 0 :(得分:0)
第1步:SearchResults
实施Parcelable
或Serializable
。
步骤2:使用getParcelableArrayList()
或getSerializable()
代替getString()
来检索附加内容Bundle
中的值。