android intent.putextras,android – 如何使用putExtra()和getExtra()字符串数据

有人可以告诉我如何确切地使用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()。我得到输入的值作为字符串,然后我必须传递这些数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值