Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:08:48+00:00 2026-06-09T14:08:48+00:00

I am triyn to implement Parcle data and send it to some other class

  • 0

I am triyn to implement Parcle data and send it to some other class through Intent but getting NULL object I am new in Android there may be some stupid mistake if yes sorry for that ….
Cretaed object and Intent passed on button click

    public class ParceableExampleActivity extends Activity implements  View.OnClickListener {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        switch(v.getId()){
        case R.id.button1:
             ParcelData p = new ParcelData();
             p.setFirstName("Kumar");
             p.setAddedBy(3);
            Intent n = new Intent(this,ResultActivity.class);
            n.putExtra("data", p);
            startActivity(n);

        }

    }
}

Parceldata which implements pacelclass

 public class ParcelData implements Parcelable {

    private String firstName ;
    private int addedBy ;
    //private UUID guid ;

    private static final String TAG = "TEST" ;
    public ParcelData() {
        firstName=null ;
        addedBy=0;
    //  guid=null;
    }

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public int getAddedBy() {
        return addedBy;
    }
    public void setAddedBy(int addedBy) {
        this.addedBy = addedBy;
    }

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

        @Override
        public Parcelable[] newArray(int size) {
             return new Parcelable[size];
        }
    } ;



    public void writeToParcel(Parcel dest, int flags) {
        Log.v(TAG, "writeToParcel..."+ flags);

        dest.writeString(firstName);
        dest.writeInt(addedBy);


    }

    public void ParcelData(Parcel in){
        readFromParcel(in);
    }

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

     private void readFromParcel(Parcel in) {

         firstName= in.readString();
         addedBy= in.readInt();
     }

    }

Receiving the Object

public class ResultActivity extends Activity implements  View.OnClickListener {



        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button button1 = (Button)findViewById(R.id.button2);
            button1.setOnClickListener(this);
        }
        @Override
        public void onClick(View v) {
            switch(v.getId()){
            case R.id.button2:
                Bundle b = getIntent().getExtras();
                ParcelData result_p=b.getParcelable("data");
                Log.v("RESULT", "result of Parcel..."+ result_p.getFirstName());
                Log.v("RESULT", "result of Parcel..."+ result_p.getAddedBy());

            }

        }
    }

but the result of the logs are NULL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:08:50+00:00Added an answer on June 9, 2026 at 2:08 pm

    This has to be a constructor. You have to remove void:

    public ParcelData(Parcel in){
        readFromParcel(in);
    }
    

    Otherwise it will be seen as a method and not used.

    The creator has to look like this:

    public static final Parcelable.Creator<ParcelData> CREATOR = new Parcelable.Creator<ParcelData>() {
      public ParcelData createFromParcel(Parcel source) {
            return new ParcelData(source);
      }
      public ParcelData[] newArray(int size) {
            return new ParcelData[size];
      }
    }
    
    @Override
    public ParcelData[] newArray(int size) {
         return new ParcelData[size];
    }
    

    You also don’t need default constructor. The variables are initialized to these values anyways. And I don’t know if maybe it causes problems with the framework.

    //remove
    public ParcelData() {
        firstName=null ;
        addedBy=0;
    //  guid=null;
    }
    

    In describeContents it might help if you use the hashCode:

    @Override
    public int describeContents() {
        return hashCode();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to ocaml and tryin to write a continuation passing style function but
I am tryin to add data to my list object. For a string, I
We're tryin to implement some kind of feedback, which I saw in MSDN web-site.
im tryin to send a 2d array in simple socket program..but this only sends
tryin to read dir content with readdir($myDirectory), but i getting error: readdir(): supplied argument
i'm triyin to match some phrase inside a string as a word (stristr doesn't
I'm tryin to grasp the fundamentals of Cocoa (Iphone) MVC design, but it's being
Please excuse my newbie Question. I'm tryin to display data from a mysql table
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
I've been tryin to find an example of the syntax for getting an html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.