首先修改values\strings.xml文件

代码如下:

<resources>

    <string name="app_name">mytab</string>

    <string name="menu_settings">Settings</string>

	<string name="app_title">Intent操作</string>
<string name="send_name">发送Intent的Activity程序.</string>
<string name="receive_name">接收Intent的Activity程序.</string>
</resources>

  然后定义send_main.xml文件

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/MyLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/mybut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按下将跳转到另一个Activity程序"/>
</LinearLayout>

  相应的定义Send.java类

代码如下:

package com.example.mytab;

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 Send extends Activity {
private Button mybut = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_main);
this.mybut = (Button)super.findViewById(R.id.mybut);
this.mybut.setOnClickListener(new OnClickListenerlmpl());
}
public class OnClickListenerlmpl implements OnClickListener{
public void onClick(View view){
Intent it = new Intent(Send.this,Receive.class);
it.putExtra("myinfo", "嗨,朋友");
Send.this.startActivity(it);
}
}
}

  对于Receive,有相应的定义

首先receive_main.xml文件

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MyLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

  然后定义Receive.java类

代码如下:

package com.example.mytab;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class Receive extends Activity{
private TextView show = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
super.setContentView(R.layout.receive_main);
this.show = (TextView)super.findViewById(R.id.show);
Intent it = super.getIntent();
String info = it.getStringExtra("myinfo");
this.show.setText(info);
}
}

  最后需要修改相应的Mainifest.xml文件,增加新的Activity程序

代码如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mytab"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="15" /> <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="Send"
android:label="@string/send_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Receive"
android:label="@string/receive_name"/>
</application> </manifest>

  运行效果:

点击后跳转到另一个Activity类中,并传递消息

android之初识Intent的更多相关文章

  1. Android安全之Intent Scheme Url攻击

    0X01 前言 Intent scheme url是一种用于在web页面中启动终端app activity的特殊URL,在针对intent scheme URL攻击大爆发之前,很多android的浏览 ...

  2. Android学习之 Intent详解

    一. Intent 作用 Intent 是一个将要执行的动作的抽象的描述,一般来说是作为参数来使用,由Intent来协助完成android各个组件之间的通讯.比如说调用startActivity()来 ...

  3. Android中的Intent详解

    前言: 每个应用程序都有若干个Activity组成,每一个Activity都是一个应用程序与用户进行交互的窗口,呈现不同的交互界面.因为每一个Acticity的任务不一样,所以经常互在各个Activi ...

  4. Android 消息广播Intent传递数据

    1.创建布局文件activity_broadcast.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

  5. Android总结篇——Intent机制详解及示例总结

         最近在进行android开发过程中,在将 Intent传递给调用的组件并完成组件的调用时遇到点困难,并且之前对Intent的学习也是一知半解,最近特意为此拿出一些时间,对Intent部分进行 ...

  6. Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面

    现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent ...

  7. 【转】Android Activity和Intent机制学习笔记----不错

    原文网址:http://www.cnblogs.com/feisky/archive/2010/01/16/1649081.html Activity Android中,Activity是所有程序的根 ...

  8. android隐式intent使用场景解析

    Android 隐式intent相信大家都有用过,大部分场景我们用显式intent已经能满足我们的业务需求,隐式intent大部分都是用来启动系统自带的Activity或Service之类的组件.昨天 ...

  9. Android Activity和Intent机制学习笔记

    转自 http://www.cnblogs.com/feisky: Activity Android中,Activity是所有程序的根本,所有程序的流程都运行在Activity之中,Activity具 ...

随机推荐

  1. jstl数字转日期

    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <jsp: ...

  2. coco2dx加载网络图片并保存

    直接上代码 bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::i ...

  3. iOS7 和 iOS6的页面兼容问题

    ios7 的status bar变透明了,各个bar也透明了,一个controller的view占据了整个屏幕.怎么调整呢?基本的思想是把内容的坐标下移.如果仅仅把内容的y坐标下移,那么在ios6上显 ...

  4. 1.django笔记之django基础

    一.django简介 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内 ...

  5. 高效开发 Android App 的 10 个建议(转)

    文章写的非常好,值得大家好好研究研究,仔细分析一下. 引文地址: http://www.cnblogs.com/xiaochao1234/p/3644989.html 假如要Google Play上做 ...

  6. 二、JavaScript语言--JS基础--JavaScript入门篇

    1.如何插入JS 使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<scri ...

  7. 二进制日志BINARY LOG清理

    mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------- ...

  8. PHP常用类型判断函数

    1.gettype():获取变量类型 2.is_array():判断变量类型是否为数组类型 3.is_double():判断变量类型是否为倍浮点类型 4.is_float():判断变量类型是否为浮点类 ...

  9. AngularJS深入(5)——provider

    太精彩,不得不全文引用. 到这个层次,可能才敢说自己懂了吧... http://syaning.com/2015/07/21/dive-into-angular-5/ 在使用AngularJS的时候, ...

  10. 在linux上安装psycopg2出错--Error: pg_config executable not found.

    这个错误可能是因为缺少PGSQL的相关库吧. 网上有很多解决办法,我最终用以下方式解决: yum install postgresql postgresql-devel python-devel