《转》

今天主要学习了Activity 组件,在这里作一下总结

1,学习如何创建Activity

创建 Activity 要点:

(1) 一个Activity就是一个类,并且这个类要继承Activity

(2) 需要复写onCreate() 方法

(3) 每一个Activity都需要在AndroidManifest.xml文件中进行配置

(4) 为Activity添加必要的控件

下面来看一个实例:

对应的 main.xml 文件

//----------------------------------main.xml-----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" /> <Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

2,多个Activity 之间的关系

多个Activity之间通过Intent来传递信息

Intent 的基本作用

一个 Intent 对象包含了一组信息

(1) Component name 指定要启动啊一个 Activity

(2) Action 指定的Activity 要做什么

(3) Data 一个Activity 向另一个Activity 中传递怎样的数据

(4) Extras 接收者Activity 可以从 Intent 中取出发送方 Activity 的键值对

(5) Categories

(6) Flags

Intent 可以用于两个Activity 之间传递信息,这两个Activity 不一定是一个应用程序的两个界面,也可是不同的两个应用程序的界面。主要是一些系统调用会比较常用这种方式去调用。

下面来看一个实例

Activity_02.java

//----------------------------------main.xml-----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" /> <Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

OtherActivity.java 文件

//------------------------------------------------OtherActivity.java------------------------------------
package csdn.Activity2; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class OthersActivity extends Activity {
private TextView myTextView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.others);
Intent intent = getIntent();
String value = intent.getStringExtra("testIntent"); myTextView = (TextView)findViewById(R.id.myTextView);
//myTextView.setText(R.string.other);
myTextView.setText(value);
} }

清单文件可以参考:http://www.cnblogs.com/McCa/p/4497928.html

如何实现两个Activity 之间如何通讯的更多相关文章

  1. Android中两个Activity之间简单通信

    在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...

  2. 两个Activity之间共享数据、互相访问的另一种方式的实现

    本帖最后由 勇敢的心_ 于 2010-9-29 11:51 编辑 本人从windows编程转过来学习Android开发,一直在想如果两个Activity之间能够像C#或delphi中的Form一样,可 ...

  3. 【转】 android之如何在两个activity之间传递handler_利用broadcast广播机制

    原文:http://blog.csdn.net/jason0539/article/details/18075293 这算是如何在两个activity之间传递handler的解决方案二了,解决方案一见 ...

  4. (WCF) 利用WCF实现两个Process之间的通讯。

    目的: 实现两个独立的Process 之间的通讯. 实现思路: 建立一个WCF Service,然后将其Host到一个Console 程序中,然后在另外一个Console程序中引用WCF的Servic ...

  5. 两个进程之间的通讯——pipe 管道

    在实际工作中,已经编辑好了NIPT_analysis的软件,该软件一般的输入文件是sam文件,但是为了集成进入测序仪器,需要直接从比对软件的标准输出中读取sam文件,省去了比对软件和NIPT_anal ...

  6. 两个 Activity 之间跳转时必然会执行的是哪几个方法?

    一般情况下比如说有两个 activity,分别叫 A,B,当在 A 里面激活 B 组件的时候, A 会调用 onPause()方法,然后 B 调用 onCreate() ,onStart(), onR ...

  7. 两个activity之间传递数据用startActivityForResult方法。

    package com.example.testactivityresquest; import android.app.Activity; import android.content.Intent ...

  8. 如何在两个activity之间传递bitmap

    1.需求 在项目开发过程中,打印小票前需要添加打印预览功能,交易数据在打印前转成bitmap然后直接打印,为了显示这个bitmap需要将其传给显示activity. 2.解决方法 把bitmap存储为 ...

  9. 两个Activity之间的交互startActivityForResult的使用

    代码如下: package com.zzw.teststartintentforrequest; import android.app.Activity; import android.content ...

随机推荐

  1. WindowsCE project missing - 转

    00x0 前言 之前在Windows 7系统中开发的WindowsCE项目,最近换成Windows 10系统,需要将项目进行修改,打开项目后提示如下错误: 无法读取项目文件“App.csproj”.. ...

  2. Socket模型详解(转)

    两种I/O模式 一.选择模型 二.异步选择 三.事件选择 四.重叠I/O模型 五.完成端口模型 五种I/O模型的比较 两种I/O模式 1. 两种I/O模式 阻塞模式:执行I/O操作完成前会一直进行等待 ...

  3. SharePoint 2013中修改windows 活动目录(AD)域用户密码的WebPart(免费下载)

    前段时间工作很忙,好久没更新博客了,趁国庆休假期间,整理了两个之前积累很实用的企业集成组件,并在真正的大型项目中经受住了考验:.Net版SAP RFC适配器组件和SharePoint 2013修改AD ...

  4. toad 常用快捷键与配置

    F8 调出以前执行的sql命令 F9 执行全部sql Ctrl+. 补全table_name Ctrl+t 补全table_name,或者显示字段 alt+ 箭头上下 看sql history Ctr ...

  5. [原]零基础学习在Android进行SDL开发系列文章

    [原]零基础学习SDL开发之移植SDL2.0到Android [原]零基础学习SDL开发之在Android使用SDL2.0显示BMP图 [原]零基础学习SDL开发之在Android使用SDL2.0显示 ...

  6. 强(strong)、软(soft)、弱(weak)、虚(phantom)引用

    https://github.com/Androooid/treasure/blob/master/source/lightsky/posts/mat_usage.md 1.1 GC Root JAV ...

  7. oracle监听程序无法启动(TNS-12560: TNS: 协议适配器错误,TNS-00530: 协议适配器错误)

    问题描述1:   C:\Users\Administrator>lsnrctl start LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Pr ...

  8. smartjs - DataManager API

    dataServices 数据服务的管理器:首先看下具体的代码 //数据服务 dataServices = st.factory({ name: "dataServices", p ...

  9. 【翻译】C# Tips & Tricks: Weak References - When and How to Use Them

    原文:C# Tips & Tricks: Weak References - When and How to Use Them Sometimes you have an object whi ...

  10. MongoDB的学习--文档的查询

    继续关于<MongoDB权威指南>记录,今天的内容是文档的查询~~ MongoDB官网地址:http://www.mongodb.org/ 我使用的是MongoDB 2.4.8 find函 ...