首先修改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. php 今天 昨天 明天 时间戳

    2013年9月10日 16:26:25 echo strtotime('now'),'<br>'; echo strtotime('today'),'<br>'; echo s ...

  2. Windows下使用命令行设置ip地址的DNS服务器

    使用命令行或者编写bat批处理设置网络连接的IP地址以及DNS服务器地址有时候会比手动更加方便,IP地址和DNS的设置一般是配合的,常用到的几个状态是: 1.IP地址动态获取,DNS也动态 2.IP地 ...

  3. Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法

    在Android开发中,ListView有着很重要的地位,使用的场合也非常的多 错误提示:Your content must have a ListView whose id attribute is ...

  4. August 6th, 2016, Week 32nd, Saturday

    It is not the mountain we conquer, but ourselvess. 我们征服的不是高山,而是我们自己. Difficulties and obstacles, jus ...

  5. HTTP状态码整理

    状态消息 1xx:信息 消息 描述 100 Continue 服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求,客户端应该继续发送其余的请求. 101 Switching Protocols 服 ...

  6. Java并发编程:Synchronized及其实现原理

    Java并发编程系列: Java 并发编程:核心理论 Java并发编程:Synchronized及其实现原理 Java并发编程:Synchronized底层优化(轻量级锁.偏向锁) Java 并发编程 ...

  7. Android之canvas详解

    首先说一下canvas类: Class Overview The Canvas class holds the "draw" calls. To draw something, y ...

  8. Android数据存储之sharedpreferences与Content Provider

    android中对数据操作包含有: file, sqlite3, Preferences, ContectResolver与ContentProvider前三种数据操作方式都只是针对本应用内数据,程序 ...

  9. wait() 与 sleep

    1.对于两种方法区别 1. 这两个方法来自不同的类,sleep方法属于Thread,wait方法属于Object. 2. 最主要是sleep方法没有释放锁,而wait方法释放了锁,使得其他线程可以使用 ...

  10. Android中获取蓝牙log

    1.蓝牙的snoop log存放位置 /etc/bluetooth/bt_stack.conf   2.修改方法 #关闭蓝牙 修改bt_stack.conf文件中打印log的等级 adb root a ...