Android : Android Error Simple (2 Activities)

on Sunday, October 26, 2014


I have 2 activities: I am just getting input from 1st activity and posting into 2nd.


In my first activity, I have :



Intent intent = new Intent(this,SecondActivity.class);
EditText editText = (EditText) findViewById(R.id.textBoxFirstActivity);
String message = editText.getText().toString(); ----Line 1
intent.putExtra(EXTRA_MESSAGE,message); -----Line 2
startActivity(intent);


where SecondActivity is a java file for 2nd activity. textBoxFirstActivity is the ID of EditText in 1st one.


In SecondActivity.java, I have :



Intent intent1 = getIntent();
String msg = intent1.getStringExtra(MainActivity.EXTRA_MESSAGE);


TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(msg);


setContentView(textView);


See Above, there are 2lines - Line 1 and Line 2. When I delete Line 1 and pass a Static String to Line 2 instead of "message", it works. But, it's of no use. Please explain why this code is not working.


0 comments:

Post a Comment