android之初识Intent
首先修改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的更多相关文章
- Android安全之Intent Scheme Url攻击
		
0X01 前言 Intent scheme url是一种用于在web页面中启动终端app activity的特殊URL,在针对intent scheme URL攻击大爆发之前,很多android的浏览 ...
 - Android学习之  Intent详解
		
一. Intent 作用 Intent 是一个将要执行的动作的抽象的描述,一般来说是作为参数来使用,由Intent来协助完成android各个组件之间的通讯.比如说调用startActivity()来 ...
 - Android中的Intent详解
		
前言: 每个应用程序都有若干个Activity组成,每一个Activity都是一个应用程序与用户进行交互的窗口,呈现不同的交互界面.因为每一个Acticity的任务不一样,所以经常互在各个Activi ...
 - Android 消息广播Intent传递数据
		
1.创建布局文件activity_broadcast.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...
 - Android总结篇——Intent机制详解及示例总结
		
最近在进行android开发过程中,在将 Intent传递给调用的组件并完成组件的调用时遇到点困难,并且之前对Intent的学习也是一知半解,最近特意为此拿出一些时间,对Intent部分进行 ...
 - Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
		
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent ...
 - 【转】Android Activity和Intent机制学习笔记----不错
		
原文网址:http://www.cnblogs.com/feisky/archive/2010/01/16/1649081.html Activity Android中,Activity是所有程序的根 ...
 - android隐式intent使用场景解析
		
Android 隐式intent相信大家都有用过,大部分场景我们用显式intent已经能满足我们的业务需求,隐式intent大部分都是用来启动系统自带的Activity或Service之类的组件.昨天 ...
 - Android Activity和Intent机制学习笔记
		
转自 http://www.cnblogs.com/feisky: Activity Android中,Activity是所有程序的根本,所有程序的流程都运行在Activity之中,Activity具 ...
 
随机推荐
- kettle转换JavaScript获取命令行参数
			
日常开发中由于很多参数是变化的,需要在部署时才能确定.而写在配置文件里又显得很笨重,因而可以运行时实时指定.那么kettle是怎么获取命令行中的参数的呢? kettle可以通过转换里的JavaScri ...
 - Android dp px转化公式
			
// DisplayMetrics metrics = getResources().getDisplayMetrics(); // int statusBarHeight = (int) Math. ...
 - php开发网站编码统一问题
			
一个良好的网站代码整洁,注释适当是最基本的,也是好的习惯,这可以避免以后的非常乱了自己感觉都乱,一旦重构麻烦就大了耗时耗力,其中网站整个体系的编码是最重要的一个方面,为了网站的稳定性建议php程序,H ...
 - July 28th, Week 31st Thursday, 2016
			
Time is a bird flying into eternity. 时间是一只永远在飞翔的鸟儿. Time waits for nobody. Vitality shows in not onl ...
 - tuple元组(C++11及以后,如C++14)
			
类tuple与array最本质的区别当数tuple元组元素类型可以不一样,而统一数组array的元素类型必须一样. 本文主要举例: tuple_size Example 123456789101112 ...
 - Mongodb安装(Mac平台)
			
1安装: sudo brew install mongodb 2 启动MongoDb sudo mongod —config /usr/local/etc/mongod.conf 3.登录mongo ...
 - a个人经验总结
			
个人经验总结 js中事件有个 on前缀 比如 onclick onmousemove jq中事件省略 on 如 click mousemove html引入其他页面 <iframe src= ...
 - FileUpload之FileItem
			
转自:http://asialee.iteye.com/blog/706079 FileItem类主要是封装了一个File Item或者是FormItem,它的主要的方法如下,需要说明的是对于Form ...
 - Struts2文件上传和下载(原理)
			
转自:http://zhou568xiao.iteye.com/blog/220732 1. 文件上传的原理:表单元素的enctype属性指定的是表单数据的编码方式,该属性有3个值:1) ...
 - Python 中的函数与类的方法
			
注:本文转译自 Stackoverflow 上 Adding a Method to an Existing Object 的最佳回答. 在 python 中,def 定义的函数与类中的方法有很大的不 ...