menu_on_top
menu_on_top

Reputation: 2613

how to move data between 2 activities

i have a first screen in my app that the user enter his name in an editText.Then, when the user presses the button "ok",the app is going to a new activity.I would like to get the text from the first activity and move it to the second.For example,if the user fills the edittext with the name "kostas",when he goes to the second activity,to appear a textView writing "Hello kostas"..

i have tried to use putExtra, but i m thinking that i m doing it in a wrong way.In the first class i m using this

Button ok = (Button) findViewById(R.id.ok);
        ok.setOnClickListener(new View.OnClickListener() {

            public void onClick (View view) {

                 Intent newActivity = new Intent(view.getContext(),home.class);

                newActivity.putExtra("NAME", name);
                    startActivity(newActivity);

            }  

        });

in order to move the name into my next activity "home".but then i dont know how to get it there...

and then in my new "home" activity i m using this:

 Bundle extras = getIntent().getExtras();

        String Name = extras.getString("NAME");

Upvotes: 0

Views: 647

Answers (1)

JAL
JAL

Reputation: 3319

First, in your onClick Handler I would extract the text from the editText box and place the text into the intent.

Second, to debug the problem I would enable LogCat viewing

Third, I would log the actual values being passed (in Act 1) and extracted ( in Act 2) using a call such as:

Log.d(TAG,name);

Hope that helps, JAL

Upvotes: 1

Related Questions