• Intent——切换activity

    intent.setClass(first.this,second.class);
    startActivity(intent);
  • Bundle——切换时数据传递

    //跳转
    Intent intent = new Intent();
    //跳转时数据传输
    Bundle bundle = new Bundle();
    intent.setClass(MainActivity.this, SecondActivity.class);
    bundle.putString("message", str);
    intent.putExtras(bundle);
    startActivity(intent);
    Bundle bundle = this.getIntent().getExtras();
    String message = bundle.getString("message");

Source Code:

package com.example.intent;

import android.os.Bundle;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends Activity { private EditText myText; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button button = (Button)findViewById(R.id.button1);
myText = (EditText)findViewById(R.id.editText1); button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { String str = myText.getText().toString();
//跳转
Intent intent = new Intent();
//跳转时数据传输
Bundle bundle = new Bundle(); intent.setClass(MainActivity.this, SecondActivity.class);
bundle.putString("message", str);
intent.putExtras(bundle); startActivity(intent); }
}); } }

MainActiviy.java

package com.example.intent;

import android.app.Activity;
import android.os.Bundle;
import android.view.TextureView;
import android.widget.TextView; public class SecondActivity extends Activity{ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second); Bundle bundle = this.getIntent().getExtras();
String message = bundle.getString("message"); TextView myText = (TextView)findViewById(R.id.textView2);
myText.setText(message); } }

SecondAcitivity.java

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Intent</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="Tree">TreeDream</string> </resources>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Tree" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" /> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/x" /> </LinearLayout>

second.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="51dp"
android:text="Turn to the secondActivity." /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:ems="10" > <requestFocus />
</EditText> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/textView1"
android:src="@drawable/y" /> </RelativeLayout>

activity_main.xml

Android——Intent,Bundle的更多相关文章

  1. Android中Bundle和Intent的区别

    Bundle的作用,以及和Intent的区别: 一.Bundle: A mapping from String values to various Parcelable types 键值对的集合 类继 ...

  2. android Intent介绍

    Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 ...

  3. Android Intent (可通过URL启动 Activity)

    Intent分为两大类: (1)显性的(Explicit) (2)隐性的(Implicit) 对于隐性意图,在某些时候, 应用程序只是想启动具有某种特征的组件, 并不想和某个特定的组件耦合. 使用In ...

  4. Android之Bundle类

    API文档说明 1.介绍 用于不同Activity之间的数据传递 1.重要方法 clear():清除此Bundle映射中的所有保存的数据. clone():克隆当前Bundle containsKey ...

  5. android Intent.ACTION_SEND

    ACTION_SEND intent 可以把自己的应用添加到系统的发送(分享)列表中. <intent-filter> <action android:name="andr ...

  6. [Android] Intent详解

    [转]http://www.cnblogs.com/engine1984/p/4146621.html [正文] Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重 ...

  7. 关于android中Bundle的使用

      1.Android using Bundle for sharing variables 注:android中使用Bundle来共享变量,下例中Activity1和Activity2通过bundl ...

  8. Android Intent 用法全面总结

    [代码全屏查看]-Android Intent 用法全面总结 // [1].[代码] 调用拨号程序 跳至 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] / ...

  9. 【转】Android Intent Action 大全

    String ADD_SHORTCUT_ACTION 动作:在系统中添加一个快捷方式.. “android.intent.action.ADD_SHORTCUT” String ALL_APPS_AC ...

随机推荐

  1. 笔记_JSON

    解析 JSON 步骤 如果没有自带 , 就添加 第三方包 (JavaScript编程语言本身自带解析JSON的能力) 一般是要手写 : 实体类 JSON -> 实体类  中间映射 Gson的话 ...

  2. 牛客网Java刷题知识点之equals和hashcode()

    不多说,直接上干货! 福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑          ...

  3. 阿里云Centos 7上面安装mysql教程

    1 软件的基本安装过程 1 卸载已有的mysql 1.查看系统是否安装了mysql软件 rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用 ...

  4. 【ExtJS】关于自定义组件(一)

    一.目的: ExtJS中提供了下拉日期选择控件Ext.form.field.Date与下拉时间选择控件Ext.form.field.Time.不过没有一个在选择日期时选择时间的控件datetimefi ...

  5. [實現DDD] 第10章 聚合(1)設計原則

    聚合只是將一些實體(Entity)與值對象(Value Object)聚集起來的對象樹嗎?? 有些途徑可能使我們設計出不正確的聚合模型, 如:可能為了對象組合上的方便而將聚合設計的很大;也可能設計的聚 ...

  6. Redis启动和关闭

    带配置文件启动 ./redis-server redis.conf 关闭 无密码模式  ./redis-cli -h xxx -p xxx shutdown 密码模式  ./redis-cli -h ...

  7. PHP流程控制之goto语句

    goto 操作符可以用来跳转到程序中的另一位置.该目标位置可以用目标名称加上冒号来标记,而跳转指令是 goto 之后接上目标位置的标记.PHP 中的 goto 有一定限制,目标位置只能位于同一个文件和 ...

  8. Nginx下载安装

    系统环境:win7 nginx:1.11.4 1.下载Nginx 下载地址:http://nginx.org/en/download.html 2.将压缩包解压到相应位置 3.启动nginx服务,ng ...

  9. 循环结构 while

    while 循环语句可以根据某些条件重复执行一条t-sql 语句或一个语句块 语法: while (条件) begin 语句或语句块 end 程序调试 alt+f5 启动调试 f9 切换断点  f10 ...

  10. C#-01.语法基础

    a. 语法基础 i. 命名空间(namespace):是 C# 中组织代码的方式,用来声明命名空间 . 语法:namespace 命名空间名称{ //命名空间的声明 } . 作用:可以把紧密相关的一些 ...