1

I want on the first Activity (in the layout to write) what is your name?! when a person write his name when he movie to anther Activity it should appear Hello(THE NAME)! how should i do this?

Shikiryu
  • 10,180
  • 8
  • 49
  • 75
Eva
  • 11
  • 2

2 Answers2

3

This is how you call the intent with a parameter

Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);
Alya'a Gamal
  • 5,624
  • 19
  • 34
2
public class MainActivity extends Activity {
     @Override
    public void onCreate(Bundle savedInstanceState) {
          //some stuff

          //Note : start the activity from an event (onClick per example)
          String stringObject = "Foo"; //or a String you get from your editText
          Intent i = new Intent(MainActivity.this, OtherActivity.class);
           i.putExtra("name", stringObject);
           startActivity(i);
     }
}



public class OtherActivity extends Activity {
         @Override
        public void onCreate(Bundle savedInstanceState) {
              //some stuff

               Bundle extras = getIntent().getExtras(); 
               String name = "";

               if (extras != null){
                name = extras.getString("name");
                myTextView.setText(name);
              }

         }
    }
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
  • Intent i = new Intent(MainActivity.this, OtherActivity.class); i.putExtra("name", is that the name that i have?); startActivity(i); – Eva May 14 '13 at 14:08
  • stringObject represents the name you get of the user. You have to stock this name in a `String` object. Example : `String stringObject="Foo";` – Alexis C. May 14 '13 at 14:09
  • also in the anther activity i have a textview in the layout(what should i do to apper ) the name:a sentence! – Eva May 14 '13 at 14:10
  • `myTextView.setText(stringObject);` – Alexis C. May 14 '13 at 14:11
  • should i write myTextView.setText(stringObject+"any thing i want?"); – Eva May 14 '13 at 14:15
  • WOW thanq! :))))))) u r very fastt – Eva May 14 '13 at 14:16
  • Intent i = new Intent(MainActivity.this, OtherActivity.class); i.putExtra("name", stringObject); startActivity(i); thats on the first but on the second i put myTextView.setText(stringObject);stringObject that from the first and when i do this its comes red under stringObject – Eva May 14 '13 at 14:21
  • what i should do in this case? – Eva May 14 '13 at 14:22
  • i did what u showed me now i will c, running the broject on the imlutor – Eva May 14 '13 at 14:34