android - How to pass extra data from this activity to the next activity? -


how pass data activity?

public class detailactivity extends activity {     @override     public void onbackpressed() {     }      @suppresslint("nextapi")     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_detail);         button btnforum = (button) findviewbyid(r.id.btnforum);         button btnkuis = (button) findviewbyid(r.id.btnkuis);          if (android.os.build.version.sdk_int > 9) {             strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();             strictmode.setthreadpolicy(policy);         }          showinfo();          final button btnlogout = (button) findviewbyid(r.id.btnback);         btnlogout.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 intent newactivity = new intent(detailactivity.this,mainactivity.class);                 startactivity(newactivity);             }         });          btnforum.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {                 intent forum = new intent(detailactivity.this, forum.class);                    ;                 startactivity(forum);                }          });          btnkuis.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             intent kuis = new intent(detailactivity.this, kuisioner.class);                 ;             startactivity(kuis);                 }         });     }      public void showinfo(){         final textview tnrp = (textview)findviewbyid(r.id.txtnrp);         final textview tname = (textview)findviewbyid(r.id.txtname);         final textview tsmt = (textview)findviewbyid(r.id.txtsmt);         final textview tstatus = (textview)findviewbyid(r.id.txtstatus);          string url = "http://xxx/blabla/getid.php";          intent intent = getintent();         string mhsid = intent.getstringextra("idm");          list<namevaluepair> params = new arraylist<namevaluepair>();         params.add(new basicnamevaluepair("smhsid", mhsid));          string resultserver  = gethttppost(url,params);          string strmemberid = "";         string strnrp = "";         string strpassword = "";         string strname = "";         string strsmt = "";         string strstatus = "";          jsonobject c;         try {             c = new jsonobject(resultserver);              strnrp = c.getstring("idm");             strname = c.getstring("nama-mahasiswa");             strsmt = c.getstring("semester");             strstatus = c.getstring("status-mahasiswa");              if(!strmemberid.equals(""))             {                 tnrp.settext(strnrp);                 tname.settext(strname);                 tsmt.settext(strsmt);                 tstatus.settext(strstatus);             }             else             {                 tnrp.settext("-");                 tname.settext("-");                 tsmt.settext("-");                 tstatus.settext("-");                    }         } catch (jsonexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     }      public string gethttppost(string url,list<namevaluepair> params) {         stringbuilder str = new stringbuilder();         httpclient client = new defaulthttpclient();         httppost httppost = new httppost(url);          try {             httppost.setentity(new urlencodedformentity(params));             httpresponse response = client.execute(httppost);             statusline statusline = response.getstatusline();             int statuscode = statusline.getstatuscode();             if (statuscode == 200) { // status ok                 httpentity entity = response.getentity();                 inputstream content = entity.getcontent();                 bufferedreader reader = new bufferedreader(new inputstreamreader(content));                 string line;                 while ((line = reader.readline()) != null) {                     str.append(line);                 }             } else {                 log.e("log", "failed download result..");             }         } catch (clientprotocolexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }         return str.tostring();     }      @override     public boolean oncreateoptionsmenu(menu menu) {         getmenuinflater().inflate(r.menu.main, menu);         return true;         }     } 

this detailactivity have data previous activity, need pass data "idm" kuisioner activity. can teach me how that? please important me :(

declare string mhsid class level member field like,

public class detailactivity extends activity {   private string mhsid = null; 

now in showinfo intent data like,

public void showinfo(){         ....         intent intent = getintent();         mhsid = intent.getstringextra("idm");         .... 

and pass values of mhsid kuisioner activity using putextra() via intent did in previous activity

btnkuis.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             intent kuis = new intent(detailactivity.this, kuisioner.class);                kuis.putextra("idm",mhsid);                           startactivity(kuis);                 }         }); 

and string idm in kuisioner activity same activity.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -