Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!
I want to wrap complex object(like Context) into parcelable's wrapper. When I try to convert my parcelable wrapper to parcelable wrapper I get error!
Code snippet:
My parcelable class:
public class ParcelableContext {	

	    private Context mVal;

	    public ParcelableContext(Context val) {
	    	System.out.println("PARCELABLE CONSTRUCTOR");
	        mVal = val;
	    }

	    public static final Parcelable.Creator<parcelablecontext> CREATOR =
	        new Parcelable.Creator<parcelablecontext>() {
	        public ParcelableContext createFromParcel(Parcel in) {
	        	System.out.println("PARCELABLE INSIDE");
	            Object obj = in.readValue(ParcelableContext.class.getClassLoader());
	            if(obj==null) System.out.println("PARCELABLE object is NULL");
	            else System.out.println("PARCELABLE object is not NULL");
	            Context s = (Context) obj;
	            if(s==null) System.out.println("PARCELABLE s is NULL");
	            else System.out.println("PARCELABLE s is not NULL");
	            return new ParcelableContext(s);
	        }

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

	    public Context getValue() {
	    	System.out.println("PARCELABLE GET VALUE");
	        return mVal;
	    }

	    
	    public String toString() {
	        return "MyParcelable[val=" + mVal.toString() + "]";
	    }

		public int describeContents() {
			// TODO Auto-generated method stub
			return 0;
		}

		public void writeToParcel(Parcel dest, int flags) {
			// TODO Auto-generated method stub
			System.out.println("PARCELABLE WRITE");
			dest.writeValue(mVal);
		}
	
}
</parcelablecontext></parcelablecontext>

Error:
Intent i = new Intent(this, SelectAbonent.class);
Parcelable p = (ParcelableContext) new ParcelableContext(this); //Error
i.putExtra("ParcelableContext",p);

What do I wrong?
Posted
Comments
Nagy Vilmos 23-Aug-11 8:19am    
Runtime error or compile error?
More detail is needed for anyone to solve this.
_Ares!!! 24-Aug-11 6:28am    
I have runtime error. I've seen one article which explain that I can't wrap unknown objects(like Context). After that I stopped looking about this topic. Is it true?
Nagy Vilmos 24-Aug-11 6:42am    
What is the runtime error? Attach the full text to the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900