zoukankan      html  css  js  c++  java
  • android之intent学习

    Intent传值

           EditText et = (EditText)findViewById(R.id.etName);//定义的文本框。

        String aa = et.getText().toString();//获取文本框内容。

           Intent intent = new Intent();

    intent.setClass(helloworld.this,android2.class);//helloworld.class为Activity,android2.class为Activity。

    intent.putExtra("name", "传值测试!");//设置传递内容。

        startActivity(intent);//跳转。

        finish();//关闭当前Activity。

    第一种写法,用于批量添加数据到Intent:

       Intent intent = new Intent();

      Bundle bundle = new Bundle();//该类用作携带数据

      bundle.putString("name", "学习android");

       intent.putExtras(bundle);//为意图追加额外的数据,意图原来已经具有的数据不会丢失,但key同名的数据会被替换

    第二种写法:这种写法的作用等价于上面的写法,只不过这种写法是把数据一个个地添加进Intent,这种写法使用起来比较方便,而且只需要编写少量的代码。

       Intent intent = new Intent();

      intent.putExtra("name", "学习android");

        在android2的onCreate方法中取值

    【取值方法:String test= (String)(this.getIntent().getExtras().getString("name").toString());】

  • 相关阅读:
    ADC和RTC的寄存器的读取
    串口中断
    chengdongyue的笔记
    UART速度的问题
    tags
    strtok
    exports、module.exports和export、export default到底是咋回事
    module.exports与exports,export与export default之间的关系和区别
    Vue2.x中的Render函数
    Vue的入门之安装
  • 原文地址:https://www.cnblogs.com/hyzhou/p/3025837.html
Copyright © 2011-2022 走看看