Android:Activity的跳转

               // 实际开发中常用的方法
         Intent intent = new Intent();
intent.setClass(MainActivity.this, LoginActivity.class);
startActivity(intent);
               //<疯狂Android>中介绍的方法 
         ComponentName comp = new ComponentName(MainActivity.this, FullscreenActivity02.class);
Intent intent = new Intent();
intent.setComponent(comp);
startActivity(intent);

界面间传值:

        // 数据打包
Bundle bdl = new Bundle();
bdl.putString("name", "A");
bdl.putInt("years", 17);
// 跳界传参
Intent itt_1 = new Intent(this, A01_Activity.class);
itt_1.putExtras(bdl); // 起跳
startActivity(itt_1);
//-----------------------------------------------------------------
// Intent->Bundle->取值
Intent itt_2 = getIntent();
Bundle dbl = itt_2.getExtras();
String str = dbl.getString("name");
int n = dbl.getInt("years"); System.out.println(str + "●<--------------------->●" + n);

或者不直接使用Bundle传参

        // 跳界传参
Intent itt_1 = new Intent(this, A01_Activity.class);
itt_1.putExtra("name", "A");
itt_1.putExtra("years", 18); // 起跳
startActivity(itt_1);
//-------取值的地方是一样的-------------------------------------------------------------------
// Intent->Bundle->取值
Intent itt_2 = getIntent();
Bundle dbl = itt_2.getExtras();
String str = dbl.getString("name");
int n = dbl.getInt("years");
上一篇:windows环境下安装nodeJS和express,一直提示command not found-配置环境变量


下一篇:别在重复造*了,几个值得应用到项目中的 Java 开源库送给你