Android编程-利用intent进行页面跳转的两种方法

方法一

//简单页面跳转:利用ComponentName对象
//创建一个ComponentName对象
ComponentName comp=new ComponentName(MainActivity.this, TeacherLogin.class);
Intent intent=new Intent();

//为Intent对象设置Component属性
intent.setComponent(comp);
startActivity(intent);

方法二

//页面跳转+值传递
//用Bundle存储role判断是学生还是教师
Bundle bundle=new Bundle();
bundle.putString("role","教师");

//利用Intent对象跳转到login页面
Intent intent=new Intent(MainActivity.this, TeacherLogin.class);

//通过putExtras()方法传递Bundle对象,注意不要漏掉s
intent.putExtras(bundle);
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/weixin_44505462/article/details/106961159