zoukankan      html  css  js  c++  java
  • android Acitivity之间的几种传值方式(^_^)

     对于开发app 来说,数据的传递肯定是少不了的啦,其实app 的本质就是用来呈现数据的。

     好的

     方式一  Intent.putExtra(TAG,DATA);

          应用场景   对于传送单一数据,而又只在两个Activity之间传送的的。

          发出 sendActivity

                      Intent intent=new Intent(sendActivity.this,receiveActivity.class);

                      intent.putExtra(TAG,DATA);

                      startActivity(intent);

          接收 receiveActivity

                       在receiveActivity 的onCreate() 方法下

                      String name=getIntent().getIntExtra(TAG);

           注:TAG  是一个String 的标志

                 DATA 是数据  可以是String ,int,bool等。

     

      方式二  Intent.putExtras(Bundle);

          应用场景  对与多个数据 而又只在两个Activity之间传送的的。

          发出 sendActivity

                Intent intent=new Intent(sendActivity.this,receiveActivity.class);

                Bundle bundle=new Bundle();

                bundle.putString("数据一", 数据一);

                bundle.putString("数据二", 数据二);

                bundle.putString("数据三", 数据三);

                。。。。

                intent.putExtras(bundle);

                startActivity(intent);

          接收 receiveActivity

              数据一=this.getIntent().getExtras().getString("  数据一");

              数据二=this.getIntent().getExtras().getString("  数据二");

              数据三=this.getIntent().getExtras().getString("  数据三");

              。。。。

     

           注 Bundle是一个封装数据的对象 ,不知道你们是怎么理解,我就是这样理解的可以封装很多类型的。

     方式 三 Application       

            应用场景     对与多个数据 或 但单个数据都可以 根据自己需求定义

            需要到AndroidManifest.xml  的  applicaion 节点 的android:name 属性加上 Application类名。

            

             

     

  • 相关阅读:
    LeetCode c++-- 118.杨辉三角
    LeetCode c++ --896. 单调数列
    LeetCode c++--1551. 使数组中所有元素相等的最小操作数
    LeetCode c++:1550. 存在连续三个奇数的数组
    LeetCode c++--字符串转换整数 (atoi)
    c++ 顺序容器常用知识总结
    c++基础知识之容器一:顺序容器
    小菜鸡c++ LeetCode初级算法之一——数组(删除排序数组中的重复项)
    JVM
    BATCH、事务、CLOB、BLOB
  • 原文地址:https://www.cnblogs.com/spyrx7/p/4291962.html
Copyright © 2011-2022 走看看