相关疑难解决方法(0)

如何使用putExtra()和getExtra()来表示字符串数据

有人可以告诉我如何使用getExtra()putExtra()意图吗?实际上我有一个字符串变量,比如str,它存储一些字符串数据.现在,我想将这些数据从一个活动发送到另一个活动.

  Intent i = new Intent(FirstScreen.this, SecondScreen.class);   
  String keyIdentifer  = null;
  i.putExtra(strName, keyIdentifer );
Run Code Online (Sandbox Code Playgroud)

然后在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 
        }

    }
Run Code Online (Sandbox Code Playgroud)

我知道这是一个非常基本的问题但不幸的是我被困在这里.请帮忙.

谢谢,

编辑:这里我试图从一个屏幕传递到另一个屏幕的字符串是动态的.那就是我有一个editText,我得到的字符串无论用户类型如何.然后借助于myEditText.getText().toString().我将输入的值作为字符串,然后我必须传递此数据.

android android-intent

298
推荐指数
9
解决办法
72万
查看次数

标签 统计

android ×1

android-intent ×1