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具 ...
随机推荐
- iOS 中NSOperationQueue,Grand Central Dispatch , Thread的上下关系和区别
In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central D ...
- php开发网站编码统一问题
一个良好的网站代码整洁,注释适当是最基本的,也是好的习惯,这可以避免以后的非常乱了自己感觉都乱,一旦重构麻烦就大了耗时耗力,其中网站整个体系的编码是最重要的一个方面,为了网站的稳定性建议php程序,H ...
- wx.html2.WebView在 target="_blank" or rel="external" 没有反映的解决方法
在wx.html2.EVT_WEBVIEW_LOADED中,用WebView.RunScript运行删除链接目标的脚本 javaScriptStr = '''function deleteBlank( ...
- 基于centos搭建nginx+uwsgi运行django环境
环境: CentOS 7 nginx/1.9.12 Python 2.7.5 一:安装依赖包5 yum install zlib-devel bzip2-devel pcre-devel openss ...
- JDK1.7 ConcurrentHashMap 源码浅析
概述 ConcurrentHashMap是HashMap的线程安全版本,使用了分段加锁的方案,在高并发时有比较好的性能. 本文分析JDK1.7中ConcurrentHashMap的实现. 正文 Con ...
- 一箭双雕打开Genesis
打开记事本,将如下内容填入,保存时将后缀名改为bat @ ECHO 正在清理垃圾文件...del C:\tmp\*.* /f /q@ ECHO 清理完毕@ ECHO OFF@ ECHO.@ ECHO. ...
- 移动App该如何保存用户密码(转)
原文地址:http://blog.csdn.net/hengyunabc/article/details/34623957 移动App该如何保存用户密码? 这个实际上和桌面程序是一样的. 先看下一些软 ...
- Java 四舍五入
http://www.cnblogs.com/xd502djj/archive/2011/07/21/2112683.html
- .net学习之新语法学习(匿名类和匿名方法,扩展方法,系统内置委托,Lambda表达式和linq等)
1.自动属性 Auto-Implemented Properties 2.隐式类型 var var变量不能作为全局变量使用,因为不能在编译时确定类型 3.参数默认值 和 命名参数 4.对象初始化器 ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...