Akhil Yeleswar Akhil Yeleswar - 1 year ago 196
Android Question

Passing string from edit text to another activity

I have looked through the example here on stack overflow. However, I can't get a solution that works correctly. My application still crashes. How do I pass the string from an edit text in one activity to another activity?

This is my code from the first activity:

Button btnGo = (Button) findViewById(R.id.btnGo);

btnGo.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
EditText etLocation = (EditText) findViewById(R.id.et_location);
Intent intent = new Intent();
intent.putExtra("location", etLocation.getText().toString());

Code from Second Activity:

textView1 = (TextView) findViewById(R.id.textView1);

Intent intent = getIntent();
String str = intent.getStringExtra("location");

Answer Source


Intent intent = new Intent();


Intent intent = new Intent(MyCurrentActivityClass.this, NextActivity.class);

Make sure NextActivity is in the Manifest. In the first case you're not providing enough info to start the activity.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download