Yeamin Mahmud
Yeamin Mahmud

Reputation: 67

Not receiving all values sent by putextra()

I tried to send data from one activity to another. The problem is I am not receiving all the datas. Just 3 instead of 6.PS: I am new to android development

sending data from this

Intent i=new Intent(getActivity(),PigeonInfo.class);

                    String n=p.getPigeonID();
                    String f=p.getFathersID();
                    String m=p.getMothersID();
                    String g=p.getGender();
                    String gr=p.getGroup();
                    String u=p.getPicURL();


                    i.putExtra("PID",n);
                    i.putExtra("FID",f);
                    i.putExtra("MID:",m);
                    i.putExtra("PGN:",g);
                    i.putExtra("PGR:",gr);
                    i.putExtra("PUR",u);
                    startActivity(i);

To this:

    Intent i=getIntent()
    e1.setText(i.getStringExtra("PID"));
    e2.setText(i.getStringExtra("PGR"));
    e3.setText(i.getStringExtra("PGN"));
    e4.setText(i.getStringExtra("FID"));
    e5.setText(i.getStringExtra("MID"));
    String url= i.getStringExtra("PUR");

Upvotes: 0

Views: 36

Answers (2)

Daniel Zolnai
Daniel Zolnai

Reputation: 16910

For these 3 lines you add an extra : to the end of the key:

                i.putExtra("MID:",m);
                i.putExtra("PGN:",g);
                i.putExtra("PGR:",gr);

But when you retrieve them from the intent, you don't have a : anymore in the key:

e5.setText(intent.getStringExtra("MID"));

So you can fix this by removing the extra : characters in your putExtra(...) calls. Having typo's in these keys is pretty commons. You can work around such issues by defining these keys in static fields, which you reference from both places:

class Keys {
    public static final String PIGEON_MID = "pigeon_mid"
}

...

intent.putExtra(Keys.PIGEON_MID, pigeon.getMid());

...

String mid = intent.getStringExtra(Keys.PIGEON_MID);

Upvotes: 1

Himanshu Sehgal
Himanshu Sehgal

Reputation: 97

Use getIntent() instant of intent for getting the intent value ` first Activity

Intent i=new Intent(getActivity(),PigeonInfo.class);

                    String n=p.getPigeonID();
                    String f=p.getFathersID();
                    String m=p.getMothersID();
                    String g=p.getGender();
                    String gr=p.getGroup();
                    String u=p.getPicURL();


                    i.putExtra("PID",n);
                    i.putExtra("FID",f);
                    i.putExtra("MID:",m);
                    i.putExtra("PGN:",g);
                    i.putExtra("PGR:",gr);
                    i.putExtra("PUR",u);
                    startActivity(i);


Second activity

Intent inent = getIntent();

    e1.setText(intent.getStringExtra("PID"));
    e2.setText(intent.getStringExtra("PGR"));
    e3.setText(intent.getStringExtra("PGN"));
    e4.setText(intent.getStringExtra("FID"));
    e5.setText(intent.getStringExtra("MID"));


    String url= intent.getStringExtra("PUR");`

Upvotes: 2

Related Questions