Activity跳转与传值
来源:互联网 发布:电力网络 桌游 编辑:程序博客网 时间:2024/05/24 06:01
主activity中
1、创建intent对象 通过intent中setclass方法设置跳转的activity
2、通过intent中putExtra方法设置传递的参数。
跳转后的activity
1、Intent intent = getIntent()生产intent 对象
1、创建intent对象 通过intent中setclass方法设置跳转的activity
2、通过intent中putExtra方法设置传递的参数。
跳转后的activity
1、Intent intent = getIntent()生产intent 对象
2、通过intent.getStringExtra()获得传递的的intent对象。
package com.android;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity { /** Called when the activity is first created. */private Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //实例化组件 button = (Button)findViewById(R.id.Button); button.setOnClickListener(new buttonListener()); } private class buttonListener implements OnClickListener{public void onClick(View v) {// TODO Auto-generated method stub//创建Intent对象Intent intent = new Intent();//通过putExtra传值intent.putExtra("name", "Hello Android!");intent.setClass(MainActivity.this,OtherActivity.class);//启动定义好的ActivitystartActivity(intent);} }}
package com.android;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.widget.TextView;public class OtherActivity extends Activity { /** Called when the activity is first created. */private TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.other); textView = (TextView)findViewById(R.id.TextView); Intent intent = getIntent(); //第一个activity传递的值 String content = intent.getStringExtra("name"); System.out.println(content); textView.setText(content); }}
最后添加跳转的activity配置
<activity android:name=".OtherActivity" > </activity>
- Activity跳转与传值
- Activity跳转与传值
- Activity跳转与传值
- Activity跳转与传值
- Activity跳转与传值
- Activity : 跳转与传值
- 页面跳转与传值(Activity跳转与传值)
- 页面跳转与传值(Activity跳转与传值)
- 页面跳转与传值(Activity跳转与传值)
- 页面跳转与传值(Activity跳转与传值)
- 页面跳转与传值(Activity跳转与传值)
- Activity的跳转与传值
- Activity的跳转与传值
- Activity的跳转与传值
- Activity的跳转与传值
- Activity的跳转与传值
- Activity的跳转与传值
- Activity的跳转与传值
- oracle 计划任务
- Linux内核中的进程(一)
- Android横竖屏切换onConfigurationChanged not Called 原因
- fusioncharts内存溢出解决
- 2013年,会创造百亿美元产值的6个科技趋势
- Activity跳转与传值
- ldd命令详解
- Android系统框架和几种调用流程
- 11gR2解决CRS-4530: Communications failure contacting Cluster Synchronization Services daemon
- 链表 http://hi.baidu.com/silverxinger/item/3adfff97fcff3245f14215a6
- Android应用开发揭秘的第28个程序12_4_Gfopengl3D修改版和高仿版的源码注释
- 由一些公司的笔试题目想到的---模拟电路,数字电路最基本应该知道哪些
- struts2的result-type详解
- redis的安装配置使用(二) jedis访问