How do you pass a string through 2 steps?

I need to send input from user in one action that will send it to activity2

and then activity2

send input from activity1

to activity3

. visually, it will go:

activity1

has an edit textbox that sends the input to activity2

, activity2

uses the same input, and sends it to activity3

.

(activity1) --String--> (activity2) --String--> (activity3)

      

Do I need to getIntent from activity1

and send it to activity3

from method onclick

to activity2

?

+3


source to share


2 answers


String passString= "information im sending";
Intent intent = new Intent(this, secondActivity.class);
intent.putExtras("DataKey", passString);
startActivity(intent);

//in your second activity
Intent intent = getIntent();
String recieveString = intent.getStringExtra("DataKey");

//repeat the same in your second activity but this time the string will change
Intent intent = new Intent(this, thirdActivity.class);
intent.putExtras("DataKey", recieveString);
startActivity(intent);

//in your third activity
Intent intent = getIntent();
String recieveString2 = intent.getStringExtra("DataKey");

      



+1


source


You need to pass it as an additional to the second activity:

String string  = "whatever";

Intent i = new Intent(this, Activity2.class);
i.putExtra("somename", string);
startActivity(i);

      

Then enter it in the second operation like this:



Intent intent = getIntent();
String string = intent.getExtras().getString("somename"); 

      

Then you can repeat this process in Activity2 (with some different variable names so you don't get confused later) to dispatch from the second activity and go to Activity3

+1


source







All Articles