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

  • 相关阅读:
    Linux内核学习第五周 系统调用
    Linux内核学习第三周 Linux启动过程分析
    WebStorm快捷键大全
    PAT乙级-1056. 组合数的和(15)
    PAT乙级-1043. 输出PATest(20)
    PAT乙级-1021.个位数统计(15)
    PAT乙级-1036.跟奥巴马一起编程(15)
    学习笔记-C++ STL iterator与对指针的理解-20170618
    学习笔记-Little Tips_day20170615-" " and ' '
    HTML5离线存储和本地缓存
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2617034.html
Copyright © 2011-2022 走看看