java - How to use a variable in a new activity? -


i added variable pass form first activity second one. want use info has accepted first activity, @ new activity, , save on new double variable, display permanent on textview. now, appears when clicking on regular button start new activity.

as first step, guess, need remove - "startactivity(intent1);". how should move on here?

java code: first activity (name : settings.java)

@override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_settings); }     public void onclick (view v){     intent intent = new intent(settings.this, waitressrecord.class);     startactivity(intent);   }   protected void onclickwait (view v) {      //--- casting & converting edittext "etsalarywaitress" double "doublesw".     btnwaitress =(button)findviewbyid(r.id.btnwaitress);     etsalarywaitress = (edittext) findviewbyid(r.id.etsalarywaitress);     doublesw = double.parsedouble(etsalarywaitress.gettext().tostring());     //---casting radio button(s).     rbpercentage = (radiobutton)findviewbyid(r.id.rbpercentage);     rbshekel = (radiobutton)findviewbyid(r.id.rbshekel);       if (doublesw < 100 ) {         if (rbpercentage.ischecked()) {             hafrashap = 1 - (doublesw / 100.0);             strhafper = string.valueof(hafrashap);             toast.maketext(settings.this, strhafper, toast.length_short).show();             // start secondactivity             intent intent1 = new intent(this, waitressrecord.class);             intent1.putextra(intent.extra_text, strhafper);             startactivity(intent1);         } else if (rbshekel.ischecked()) {             hafrashas = -doublesw;             strhafshek = string.valueof(hafrashas);             toast.maketext(settings.this, strhafshek, toast.length_short).show();         } else {             toast.maketext(settings.this, "לא הוזנה סוג ההפרשה", toast.length_short).show();         }     } else {         toast.maketext(settings.this, "מספר שגוי", toast.length_short).show();     } } 

new activity: (name : waitressrecord.java)

public class waitressrecord extends appcompatactivity {      string strhafper;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_waitress_record);          // text mainactivity         intent intent1 = getintent();         strhafper = intent1.getstringextra(intent.extra_text);          // use text in textview         textview textview = (textview) findviewbyid(r.id.textview);         textview.settext(strhafper);     } } 

   //first activity  intent intent= new intent(this, secondactivity.class); bundle = new bundle(); mbundle.putstring(variable_key, value); intent.putextras(mbundle);   startactivity(intent);   //on second acitivty    intent intent = getintent();  bundle bundleextra;  //null checking if (intent != null ) {  bundleextra = getintent().getextras(); // sure check "variable key same in first activity string resultstring = extras.getstring("variable_key"); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -