Reputation: 777
I have an app with two activities -> activity1 and activity2. I want the user to be able to type text into an EditText in activity2, then on the click of a button in activity2 set the value of a button in activity1 to that text and then return to activity1.
What is the best approach to doing this?
Upvotes: 0
Views: 54
Reputation: 2236
You can send some text with intent
In your activity
Intent intent=new Intent(context,Activity1.class)
intent.putExtra("buttonText",editText.getText().toString());
statActivity(intent);
and in your Activity1
in onCreate
Bundle bundle=getIntent().getExtras();
if(bundle!=null)
{
String buttonText=bundle.getString("buttonText");
button.setText(buttonText);
}
Upvotes: 1
Reputation: 9117
Start Activity2 for result. Set result from Activity2. And then in Activity's onCreate check the value, and set it.
There's a tutorial here.
http://developer.android.com/reference/android/app/Activity.html
Search for "Starting Activities and Getting Results"
Upvotes: 2