将带有位图的自定义对象传递给另一个活动?

时间:2011-11-10 07:18:02

标签: android

MyObject类

public class MemberDetailsObject implements Serializable {

String memberid;
String memberName;
String mobileNumber;
String photo;
String phoneType;
String latitute ;
String longitude;
String dateNTime;
String locationName;
String date;
String time;
Bitmap memberImage;
public String getMemberid() {
    return memberid;
}
public void setMemberid(String memberid) {
    this.memberid = memberid;
}
public String getMemberName() {
    return memberName;
}
public void setMemberName(String memberName) {
    this.memberName = memberName;
}
public String getMobileNumber() {
    return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
    this.mobileNumber = mobileNumber;
}
public String getPhoto() {
    return photo;
}
public void setPhoto(String photo) {
    this.photo = photo;
}
public String getPhoneType() {
    return phoneType;
}
public void setPhoneType(String phoneType) {
    this.phoneType = phoneType;
}
public String getLatitute() {
    return latitute;
}
public void setLatitute(String latitute) {
    this.latitute = latitute;
}
public String getLongitude() {
    return longitude;
}
public void setLongitude(String longitude) {
    this.longitude = longitude;
}
public String getDateNTime() {
    return dateNTime;
}
public void setDateNTime(String dateNTime) {
    this.dateNTime = dateNTime;
}
public String getLocationName() {
    return locationName;
}
public void setLocationName(String locationName) {
    this.locationName = locationName;
}
public String getDate() {
    return date;
}
public void setDate(String date) {
    this.date = date;
}
public String getTime() {
    return time;
}
public void setTime(String time) {
    this.time = time;
}
public Bitmap getMemberImage() {
    return memberImage;
}
public void setMemberImage(Bitmap memberImage) {
    this.memberImage = memberImage;
}
public MemberDetailsObject(String memberid, String memberName,
        String mobileNumber, String photo, String phoneType, String latitute,
        String longitude, String dateNTime, String locationName, String date,
        String time, Bitmap memberImage) {
    super();
    this.memberid = memberid;
    this.memberName = memberName;
    this.mobileNumber = mobileNumber;
    this.photo = photo;
    this.phoneType = phoneType;
    this.latitute = latitute;
    this.longitude = longitude;
    this.dateNTime = dateNTime;
    this.locationName = locationName;
    this.date = date;
    this.time = time;
    this.memberImage = memberImage;
}




}

我正在尝试使用

传递它
Intent viewProfile = new Intent(getApplicationContext(), ScreenMemberProfile.class);       
viewProfile.putExtra("memberList", memberList.get(positon)); 

然而问题是位图不可用,可能我知道任何其他替代

3 个答案:

答案 0 :(得分:1)

传递BitmapActivities是可能的,但内存非常昂贵。 您应该将其保存在外部存储器(缓存/ SD卡)上并将其路径(包含在Bitmap对象中)传递给下一个Serializable,而不是传递Activity对象。活动将该路径解码为Bitmap并相应地使用。

public class MemberDetailsObject implements Serializable {
    // other member ... 
    String memberImagePath;
    // rest of the class ...
}

有关详细信息,请参阅此处:

How to send image from one activity to another

how do you pass images (bitmaps) between android activities using bundles?

答案 1 :(得分:0)

Bitmap ist Parcelable,因此您可以将其置于Intent中。

答案 2 :(得分:0)

这是将位图发送到其他活动的最佳方式,因为位图不可用,但是实现

  

Parcelable

How can I pass a Bitmap object from one activity to another