Question

I'm kind of new to Android development.

I don't understand why the following code gives me a stackoverflowerror

Intent intent = new Intent(view.getContext(), MakeCall.class);
SipParcelable sipp = new SipParcelable(_sip);
intent.putExtra("sip", (Parcelable) sipp);

startActivity(intent);

Basically as soon as the startActivity(intent) fires, I get the following error:

enter image description here

I can get rid of the error by commenting out the third line with the putExtra() function.

I'm trying to pass my _sip object over to the MakeCall.class activity on another screen that's about to load up. I tried to follow the tutorial on how to implement a Parcelable class/object. Here's what my SipParcelable code looks like:

import com.myproject.library.SipService;
import android.os.Parcel;
import android.os.Parcelable;


public class SipParcelable implements Parcelable{

    public SipService mData;

    /* everything below here is for implementing Parcelable */

    // 99.9% of the time you can just ignore this
    public int describeContents() {
        return 0;
    }

    // write your object's data to the passed-in Parcel
    public void writeToParcel(Parcel out, int flags) {
        out.writeValue(mData);
    }

    public SipParcelable(SipService sip)
    {
        mData = sip;
    }

 // Parcelling part
    public SipParcelable(Parcel in){
        mData = (SipService) in.readValue(SipService.class.getClassLoader());

    }

    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public SipParcelable createFromParcel(Parcel in) {
            return new SipParcelable(in); 
        }

        public SipParcelable[] newArray(int size) {
            return new SipParcelable[size];
        }
    };

}

What am I doing wrong?

Was it helpful?

Solution

Your SipService class must implement parcelabe and modify how SipService object is read and written from/to pracel.

check this tutorial it might help you

http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/

You can use serialisable too… But parcelable is faster and better

NOTE: all properties of an object (if the properties are objects) that implements parcelable, must also be parcelable as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top