如何在Intents之间发送字符串?

Mar*_*ues 0 string android android-intent

我需要帮助将字符串发送到另一个活动.

public class MainActivity extends Activity implements OnClickListener{

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent myInt = new Intent(this,Receiver.class);
    myInt.putExtra("key",Event);
    startActivity(myInt);
}

Button b;
EditText Edt;
String Event;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b=(Button)findViewById(R.id.button);
        b.setOnClickListener(this);
        Edt=(EditText)findViewById(R.id.EdtText);
        Event=new String(Edt.getText().toString());             
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我想要发送到此活动的字符串事件的意图

public class Receiver extends Activity {

TextView txtV;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.receiving);
    txtV=(TextView)findViewById(R.id.txtV);
    Bundle extras = getIntent().getExtras();
    if(extras !=null) {
        String value = extras.getString("key");
    }
    txtV.setText("key");
}
}
Run Code Online (Sandbox Code Playgroud)

当我运行我的程序时,它只显示"key"但我想显示我在此活动中无法使用的String事件,尽管我在第一个intent中使用了putExtra方法.请帮助我,我知道还有很多其他类似的问题,但我仍然没有得到它.

Ira*_*lis 5

用这个:

    txtV.setText(value);
Run Code Online (Sandbox Code Playgroud)

不是这个:

    txtV.setText("key");
Run Code Online (Sandbox Code Playgroud)