java - Not able to get back to original activity using uri.parse method -
i beginner.i trying using uri.parse returning result. main java file.
package com.example.returnresult; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.textview; import android.widget.toast; public class mainactivity extends activity { int request_code=1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } public void sendmessage(view v){ intent = new intent(this,second.class); startactivityforresult(i,request_code); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if(requestcode == request_code) { if(resultcode == result_ok) { toast.maketext(this,data.getdata().tostring(), toast.length_short).show(); } } } }
this activity shows button on screen go second activity.and it's working fine.
and second java file.
package com.example.returnresult; import android.app.activity; import android.content.intent; import android.net.uri; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.textview; public class second extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_second); } public void sendback(view v){ intent = new intent(); edittext txt = (edittext)findviewbyid(r.id.age); i.setdata(uri.parse(txt.gettext().tostring())); setresult(result_ok,i); finish(); } }
this activity shows edittext field. id age. there's button below has send data first activity , show toast. button not working. i'm not able problem. please help!
you seen not have initialized button in second java file. if have should use
i.putextra("string data", uri.parse(txt.gettext().tostring()));
instead of
i.setdata(uri.parse(txt.gettext().tostring()));
also retrieve information by
data.getstringextra("string data")
instead of
data.getdata().tostring()
hope helps.
Comments
Post a Comment