Android跳转Activity

来源:互联网 发布:windows资源管理器占用 编辑:程序博客网 时间:2024/06/08 06:29

1.普通跳转

<pre name="code" class="java">Intent intent = new Intent();//初始化  intent.setClass(Post.this, Add.class); // 设置Intent的源地址和目标地址
</pre>startActivity(intent); //调用startActivity方法发送意图给系统 

2.带参数跳转

<pre name="code" class="java">Intent intent = new Intent();//初始化  intent.setClass(Post.this, Add.class); // 设置Intent的源地址和目标地址 intent.putExtra("userName", userName);//将用户名传递到Add Activity</span>startActivity(intent); //调用startActivity方法发送意图给系统 


3.带参数(数组)跳转

<pre name="code" class="java">Intent intent = new Intent();//初始化  intent.setClass(Post.this, Add.class); // 设置Intent的源地址和目标地址 Bundle ex = new Bundle();startActivity(intent); //调用startActivity方法发送意图给系统 


4.接收方接收

<pre name="code" class="java">//接收传过来的字符串Bundle bundle = getIntent().getExtras();
String userName = bundle.getString("userName");


//接收传过来的数组Bundle bundle = getIntent().getExtras();Bundle a=this.getIntent().getExtras();  name = a.getStringArray("name");//String型数组name记得初始化



Intent intent = new Intent();//初始化 intent.setClass(Post.this, Add.class); // 设置Intent的源地址和目标地址 intent.putExtra("userName", userName);//将用户名传递到Add Activity</span>startActivity(intent); //调用startActivity方法发送意图给系统
0 0
原创粉丝点击