In Android version 6.0.1, it will throw
In other version, will not throw this, but can't get other extras except parcelable. I know the reason. Because I implements Parcelable and Cloneable. If I only implements Parcelable, it's OK.
In Android version 6.0.1, it will throw
In other version, will not throw this, but can't get other extras except parcelable. I know the reason. Because I implements Parcelable and Cloneable. If I only implements Parcelable, it's OK.
Intent intent= new Intent(this, that.class);
intent.putExtra("string", parceable value);
intent.putExtra("string", Boolean value);
Intent intent= getIntent();
Boolean bool= intent.getBooleanExtra("string");
var xyz= intent.getParceableExtra("string");
Do it this way.
I use Serializable to replace Parcelable, this problem never occur. But I still want to solve it.
public class ContactEntity implements Parcelable,Cloneable{
private String contactID;
private String groupID;
private String phone;
private String name;
private String noteName;
private Integer sex;
private Long created;
private Long updated;
private Integer status;
private String orgGuid;
private String createrID;
private Integer ifSync = 0;
private Integer ifRegHx = 0;
private SpannableString phoneSS;
public ContactEntity() {
}
public ContactEntity(JsonNode jsonNode){
this.contactID = jsonNode.get("id").asText();
this.groupID = jsonNode.get("groupid").asText();
this.phone = jsonNode.get("phone").asText();
this.name = jsonNode.get("name").asText();
this.noteName = jsonNode.get("remarkname").asText();
this.sex = jsonNode.get("sex").asInt();
this.created = jsonNode.get("created").asLong();
this.updated = jsonNode.get("updated").asLong();
this.status = jsonNode.get("status").asInt();
if(jsonNode.has("ifsync")&&jsonNode.has("ifreghx")){
this.ifSync = jsonNode.get("ifsync").asInt();
this.ifRegHx = jsonNode.get("ifreghx").asInt();
}
this.orgGuid = UserConfig.getInstance().getCompany();
this.createrID = UserConfig.getInstance().getClientUserId();
}
protected ContactEntity(Parcel in) {
contactID = in.readString();
groupID = in.readString();
phone = in.readString();
name = in.readString();
noteName = in.readString();
sex = in.readInt();
created = in.readLong();
updated = in.readLong();
status = in.readInt();
orgGuid = in.readString();
createrID = in.readString();
}
public static final Creator<ContactEntity> CREATOR = new Creator<ContactEntity>() {
@Override
public ContactEntity createFromParcel(Parcel in) {
return new ContactEntity(in);
}
@Override
public ContactEntity[] newArray(int size) {
return new ContactEntity[size];
}
};
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
public SpannableString getPhoneSS() {
return phoneSS;
}
public void setPhoneSS(SpannableString phoneSS) {
this.phoneSS = phoneSS;
}
public String getContactID() {
return contactID;
}
public void setContactID(String contactID) {
this.contactID = contactID;
}
public String getGroupID() {
return groupID;
}
public void setGroupID(String groupID) {
this.groupID = groupID;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNoteName() {
return noteName;
}
public void setNoteName(String noteName) {
this.noteName = noteName;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public Long getCreated() {
return created;
}
public void setCreated(Long created) {
this.created = created;
}
public Long getUpdated() {
return updated;
}
public void setUpdated(Long updated) {
this.updated = updated;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCreaterID() {
return createrID;
}
public void setCreaterID(String createrID) {
this.createrID = createrID;
}
public String getOrgGuid() {
return orgGuid;
}
public void setOrgGuid(String orgGuid) {
this.orgGuid = orgGuid;
}
public Integer getIfSync() {
return ifSync;
}
public void setIfSync(Integer ifSync) {
this.ifSync = ifSync;
}
public Integer getIfRegHx() {
return ifRegHx;
}
public void setIfRegHx(Integer ifRegHx) {
this.ifRegHx = ifRegHx;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(contactID);
dest.writeString(groupID);
dest.writeString(phone);
dest.writeString(name);
dest.writeString(noteName);
dest.writeInt(sex);
dest.writeLong(created);
dest.writeLong(updated);
dest.writeLong(status);
dest.writeString(orgGuid);
dest.writeString(createrID);
dest.writeInt(ifSync);
dest.writeInt(ifRegHx);
}
public static class Builder {
private String contactID;
private String groupID;
private String phone;
private String name;
private String noteName;
private Integer sex;
private Long created;
private Long updated;
private Integer status;
private String orgGuid;
private String createrID;
private Integer ifSync;
private Integer ifRegHx;
public Builder withAutoID(){
this.contactID = UUID.randomUUID().toString();
return this;
}
public Builder buildGroupID(String groupID){
this.groupID = groupID;
return this;
}
public Builder buildPhone(String phone){
this.phone = phone;
return this;
}
public Builder buildName(String name){
this.name = name;
return this;
}
public Builder buildNoteName(String noteName){
this.noteName = noteName;
return this;
}
public Builder buildSex(Integer sex){
this.sex = sex;
return this;
}
public Builder buildCreated(Long created){
this.created = created;
return this;
}
public Builder buildUpdated(Long updated){
this.updated = updated;
return this;
}
public Builder buildStatus(Integer status){
this.status = status;
return this;
}
public Builder withAutoOrgGuid(){
this.orgGuid = UserConfig.getInstance().getCompany();
return this;
}
public Builder withAutoCreaterID(){
this.createrID = UserConfig.getInstance().getClientUserId();
return this;
}
public Builder buildIfSync(int ifSync){
this.ifSync = ifSync;
return this;
}
public Builder buildIfRegHx(int ifRegHx){
this.ifRegHx = ifRegHx;
return this;
}
public ContactEntity build(){
ContactEntity entity = new ContactEntity();
entity.setContactID(contactID);
entity.setGroupID(groupID);
entity.setPhone(phone);
entity.setName(name);
entity.setNoteName(noteName);
entity.setSex(sex);
entity.setCreated(created);
entity.setUpdated(updated);
entity.setStatus(status);
entity.setOrgGuid(orgGuid);
entity.setCreaterID(createrID);
entity.setIfSync(ifSync);
entity.setIfRegHx(ifRegHx);
return entity;
}
}
}
You can pass complete object as follows.
Create your Model as Parcelable
public class Response_GetReEnrolment implements Parcelable
{
public String app_id;
public String status;
protected Response_GetReEnrolment(Parcel in)
{
app_id = in.readString();
status = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeString(app_id);
dest.writeString(status);
}
@Override
public int describeContents()
{
return 0;
}
public static final Creator<Response_GetReEnrolment> CREATOR = new Creator<Response_GetReEnrolment>()
{
@Override
public Response_GetReEnrolment createFromParcel(Parcel in)
{
return new Response_GetReEnrolment(in);
}
@Override
public Response_GetReEnrolment[] newArray(int size)
{
return new Response_GetReEnrolment[size];
}
};
}
private Response_GetReEnrolment response;
Intent intent = new Intent(activity, Activity_ReEnrollment_Declaration.class);
intent.putExtra(AppConstants.INTENT_EXTRA_RE_ENROLMENT_RESPONSE, response);
startActivity(intent);
In Second Activity in onCreate
response = (Response_GetReEnrolment)getIntent().getExtras().get(AppConstants.INTENT_EXTRA_RE_ENROLMENT_RESPONSE);
ContactEntity entity = new ContactEntity();
entity.setContactID("1");
entity.setGroupID("1");
entity.setPhone("2323");
entity.setName("2323");
entity.setNoteName("2323");
entity.setSex(1);
entity.setCreated(1L);
entity.setUpdated(1L);
entity.setStatus(0);
entity.setOrgGuid("2323");
entity.setCreaterID("2323");
entity.setIfSync(0);
entity.setIfRegHx(0);
Intent intent = new Intent(activity, Activity_ReEnrollment_Declaration.class);
intent.putExtra("contact", entity);
startActivity(intent);
In Second Activity
ContactEntity entity = (ContactEntity)getIntent().getExtras().get("contact");
entity.getContactID();
I post my Intent in here.
Bundle bundle = new Bundle();
bundle.putParcelable("contact",contactEntity);
Intent intent = new Intent(AppointmentActivity.this,ReceiptBillForOnlineActivity.class);
intent.putExtras(bundle);
intent.putExtra("isAppointment",true);
startActivity(intent);
In another Activity, I want to get the Extras.
Intent intent = getIntent();
isAppointment = intent.getBooleanExtra("isAppointment",false);
currentContact = intent.getParcelableExtra("contact");
getParcelableExtra is successful, but getBooleanExtra is failed or throw Exception.