i'm quite new android programming.. , have problem.. want pass value, result null.. wonder why so.. can me? in advance. code this..
manager.java
string prize="5"; intent = new intent(manager.this, shop.class); i.putextra("key", prize); startactivity(i); shop.java
intent myintent = getintent(); string receive = myintent.getstringextra("key"); if (getintent().getextras() != null) { textview tv = (textview)findviewbyid(r.id.textview2); tv.settext(receive); } else { textview tv = (textview)findviewbyid(r.id.textview2); tv.settext("value null"); //this result //why null?? }
the function getextras() returns bundle placed in intent using putextras(b). this:
intent = new intent(manager.this, shop.class); i.putextras(new bundle()); startactivity(i); since aren't using putextras function getintent().getextras() returns null. should this:
intent myintent = getintent(); string receive = myintent.getstringextra("key"); if (receive != null) { textview tv = (textview)findviewbyid(r.id.textview2); tv.settext(receive); } else { textview tv = (textview)findviewbyid(r.id.textview2); tv.settext("value null"); //this result //why null?? }
Comments
Post a Comment