开发者

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");


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜