zoukankan      html  css  js  c++  java
  • Android 多个Activity 跳转及传参

    mainActivity 打开 OtherActivity:

    Intent intent = new Intent(getApplicationContext(), OtherActivity.class);            
    startActivity(intent); 

    mainActivity 给 OtherActivity 传参数: 

                Intent intent = new Intent(getApplicationContext(), OtherActivity.class);        
                //以下二个为OtherActivity传参数
                intent.putExtra("Name", "eboy");
                intent.putExtra("Age", 22);
                //也可以使用Bundle来传参数
                Bundle bundle = new Bundle();
                bundle.putString("Name1", "eboy1");
                bundle.putInt("Age1", 23);
                intent.putExtras(bundle);
                startActivity(intent);


     OtherActivity 接收来自 mainActivity 的参数:

            Intent intent = getIntent(); //用于激活它的意图对象
            
            String Name = intent.getStringExtra("Name");
            int Age = intent.getIntExtra("Age", 0);
            
            Bundle bundle = intent.getExtras();        
            
            String Name1 = bundle.getString("Name1");
            int Age1 = bundle.getInt("Age1");
            
            TextView textView = (TextView)this.findViewById(R.id.OtherTextView);
            textView.setText(Name + " : " + Age + "/" + Name1 + " : " + Age1);

    如果mainActivity 需要 OtherActivity关闭时返回一些值,则可使用 startActivityForResult来打开OtherActivity,具体用法以后用到时再了解。

     /Files/jxgxy/MutilActivity.rar

  • 相关阅读:
    少写代码帮你模块化方法 & 运动框架 & 简化轮播图
    JQ
    弹框&可用于判断
    移动端内容区域滚动做法总结
    数组这回事
    Bootstrap & 响应式
    谈谈this对象
    模态框中水平垂直居的问题
    图片的懒加载问题
    js中运动框架的封装
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2617034.html
Copyright © 2011-2022 走看看