Android Intent传值
来源:互联网 发布:java的发展方向 编辑:程序博客网 时间:2024/05/29 13:08
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取按钮对象 Button btnSendButton = (Button)findViewById(R.id.btnSend); btnSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); //第一参数取的是这个应用程序的Context,生命周期是整个应用 //第二个参数是要跳转的页面的全路径 intent.setClassName( getApplicationContext(), "com.by.testimageview.ReceiveActivity" ); //Bundle类用作携带数据,它类似于Map,用于存放key-value名值对形式的值 Bundle b = new Bundle(); //title就是key b.putString("title", "这里就是你要传递的内容了"); //此处使用putExtras,接受方就响应的使用getExtra intent.putExtras( b ); startActivity(intent); // 关闭当前页面 System.exit(0); //无论是exit还是finish都是可以的 //SendActivity.this.finish(); } }); } }//跳转的类public class ReceiveActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_receive); Button btnReceiveButton = (Button)findViewById(R.id.btn_send); btnReceiveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { //最后的参数一定要和发送方的相同,否则得到空值 String rString = getIntent().getExtras().getString("title"); Toast.makeText(ReceiveActivity.this, rString, Toast.LENGTH_SHORT).show(); } }); } }
0 0
- Android Intent传值
- Android--Intent传值
- Android Intent 传值 --onActivityResult
- Android Intent 传值
- Android Intent传值
- Android Intent传值
- android使用Intent传值
- Android的Intent传值
- Android intent intent-filter
- Android intent intent-filter
- Android intent intent-filter
- android-简单的intent传值
- android——Intent传值
- Android intent
- Android Intent
- Android Intent
- android Intent
- android intent
- The method getTextContent() is undefined for the type Node
- 随机网络-概述与E-R模型-(1)
- C# DataTable常用方法
- 数据结构-自平衡二叉查找树(AVL)详解
- 关于vector容器进行插入排序
- Android Intent传值
- java并发编程:join用法
- Codeforces Round #365 (Div. 2) Problem D.Mishka and Interesting sum 解题报告
- hdu 5762 Teacher Bo(暴力美学)
- sign 签名验证
- ListView用法简单学习
- codeforces 703C Chris and Road
- echars 自定义触发鼠标悬停事件
- css基础重要几点