有人可以告诉我如何确切地使用getExtra()和putExtra()Intent。实际上我有一个字符串变量说str,它存储一些字符串数据。现在,我想将此数据从一个活动发送到其他活动。
Intent i = new Intent(FirstScreen.this, SecondScreen.class);
String keyIdentifer = null;
i.putExtra(strName, keyIdentifer );
然后在SecondScreen.java中
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
TextView userName = (TextView)findViewById(R.id.userName);
Bundle bundle = getIntent().getExtras();
if(bundle.getString("strName")!= null)
{
//TODO here get the string stored in the string variable and do
// setText() on userName
}
}
我知道这是非常基本的问题,但不幸的是我被困在这里。
请帮忙。
谢谢,
编辑:这里我想从一个屏幕到另一个屏幕传递的字符串是动态的。
这是我有一个editText,我得到字符串任何用户类型。然后借助于myEditText.getText()。toString()。我得到输入的值作为字符串,然后我必须传递这些数据。