I want to send class Object to another activity which contains Latlng. But it gives exception. Below is my class which has latlng field.
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;
import com.google.android.gms.maps.model.LatLng;
import java.io.Serializable;
public class Institute implements Serializable,Parcelable {
private String instituteName;
private LatLng latLng;
protected Institute(Parcel in) {
instituteName = in.readString();
latLng = in.readParcelable(LatLng.class.getClassLoader());
}
public static final Creator<Institute> CREATOR = new Creator<Institute>() {
@Override
public Institute createFromParcel(Parcel in) {
return new Institute(in);
}
@Override
public Institute[] newArray(int size) {
return new Institute[size];
}
};
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(instituteName);
parcel.writeParcelable(latLng,PARCELABLE_WRITE_RETURN_VALUE);
}
public String getInstituteName() {
return instituteName;
}
public void setInstituteName(String instituteName) {
this.instituteName = instituteName;
}
public void setLatLng(LatLng latLng) {
this.latLng = latLng;
}
public LatLng getLatLng() {
return latLng;
}
}
And it gives me following exception
FATAL EXCEPTION: main
Process: in.thoughtsmith.jink, PID: 24906
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.thoughtsmith.jink/in.thoughtsmith.jink.InstituteDetails}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: Seed0004
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: Seed0004
at android.os.Parcel.readParcelableCreator(Parcel.java:2432)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at in.thoughtsmith.jink.Institute.<init>(Institute.java:45)
at in.thoughtsmith.jink.Institute$1.createFromParcel(Institute.java:55)
at in.thoughtsmith.jink.Institute$1.createFromParcel(Institute.java:52)
at android.os.Parcel.readParcelable(Parcel.java:2367)
at android.os.Parcel.readValue(Parcel.java:2264)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:786)
at in.thoughtsmith.jink.InstituteDetails.onCreate(InstituteDetails.kt:34)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Please help me how can i send class which contains latlng to another activity. And also please let me know is there any better way to achieve same
You need to extract your latitude and longitude from latLng
Then you can add it easely to your Parcelable