• 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. sql语句中开窗函数的使用

    开窗函数主要分为2类: 1.排序开窗函数: rank() over(partition by xxx order by yyy) //各分区按照yyy字段排序,如果yyy字段值一样,则rank值一样, ...

  2. Activemq API使用(整合spring)

    整合spring之后,主要用的就是org.springframework.jms.core.JmsTemplate的API了,在spring-jms-xxx.jar中. 引入整合需要的jar包: &l ...

  3. java将list<T>导出为xls文件

    一.action层 /** * 导出list */ @SuppressWarnings("unchecked") public void exportBatch() { reque ...

  4. (转)shell实现多级菜单脚本编写

    shell实现多级菜单脚本编写 原文:https://www.yuanmas.com/info/2gOwBPvqyb.html 这篇文章主要介绍了Shell实现多级菜单系统安装脚本实例分享,本文脚本用 ...

  5. (转)linux命令详解之useradd命令使用方法

    linux命令详解之useradd命令使用方法 原文:http://blog.csdn.net/u011537073/article/details/51987121 Linux 系统是一个多用户多任 ...

  6. Django自定义登陆验证后台

    支持邮箱/手机号/昵称登录,在django1.6.2测试成功.1.models # -*- encoding: utf-8 -*- from django.db import models from ...

  7. Linux下MySQL数据库主从同步配置

    说明: 操作系统:CentOS 5.x 64位 MySQL数据库版本:mysql-5.5.35 MySQL主服务器:192.168.21.128 MySQL从服务器:192.168.21.129 准备 ...

  8. 命令行编译java项目

    命令行编译java项目 项目名: testproj 目录 src -> cn -> busix -> test bin lib 编译项目 cd testproj javac -d . ...

  9. 【mysql】mysql数据库安装

    今天一直在测功能,整理用例,所以没有去调项目,想到之前有小伙伴求助数据库安装,还远程了一番,所以,就整理一下,数据库在测试工作中还是挺重要的,不能本地测试改个数据都去找开发小哥哥吧,是不是不太好呢,妹 ...

  10. HDU 5316——Magician——————【线段树区间合并区间最值】

    Magician Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...