Android Studio 使用Intent实现页面的跳转(带参数)

不论是在APP,仍是在网站中,页面之间的跳转都是很常见的,本文主要讲一下在APP中,如何经过Intent实现页面的跳转。函数

 

不带参数:网站

写在MainActivity页面的代码:this

1 Intent intent = new Intent();
2 intent.setClass(MainActivity.this, LoginActivity.class);//从MainActivity页面跳转至LoginActivity页面
3 this.startActivity(intent);

 

带参数:spa

写在SpendingActivity页面的代码:code

1 Intent intent=new Intent(SpendingActivity.this,ExpenseProcesActivity.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面
2 intent.putExtra("strType", 0);//参数:name、value
3 SpendingActivity.this.startActivity(intent);

 

写在ExpenseProcesActivity接收页面的代码:blog

1 private int type = 0;
2 
3 //接收传递过来的参数
4 final Intent intent = getIntent();
5 type = intent.getIntExtra("strType", 0);

 

备注:get

可传递的参数有多种类型,在接收参数的时候,也要根据传入类型,选用对应的接收函数it

传递参数的类型,Eg:class

对应的接收函数,Eg:im

相关文章
相关标签/搜索