《转》

今天主要学习了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. PSAM卡与CPU(用户卡)的操作过程

    最近我一直在研究关于通过国密PSAM卡作为安全模块来读写cpu(用户卡)的问题 其实,两者都是卡片,或者说都是从设备.它们之间是无法相互访问的. 实际上,PSAM 卡是作为秘密密钥的载体,专门执行加密 ...

  2. Apache MPM winnt

    Win32DisableAcceptEx 指令在 apache2.4 被 AcceptFilter None 取代

  3. Java NIO原理分析

    Java IO 在Client/Server模型中,Server往往需要同时处理大量来自Client的访问请求,因此Server端需采用支持高并发访问的架构.一种简单而又直接的解决方案是“one-th ...

  4. python 字符串长度

    通过内置方法len()来计算字符串的长度,注意这个计算的是字符的长度. aa = 'afebb'bb = '你'print len(aa)print len(bb)

  5. 使用hessian+protocol buffer+easyUI综合案例--登陆

    首先先简单介绍下hessian ,protocol buffer, easyUI框架 hessian: Hessian是一个轻量级的remoting on http工具,采用的是Binary RPC协 ...

  6. [CS231n-CNN] Image classification and the data-driven approach, k-nearest neighbor, Linear classification I

    课程主页:http://cs231n.stanford.edu/ Task: Challenges: _________________________________________________ ...

  7. ERB预处理ruby代码

    cucumber.yml 文件可以用erb预处理,这样允许你在cucumber.yml文件中使用ruby代码生成值.所以如果你有几个配置要用相同值时,你可以这样写 # config/cucumber. ...

  8. 加快MySQL逻辑恢复速度的方法和参数总结

    日常工作中经常会有需要从mysqldump导出的备份文件恢复数据库的情况,相比物理备份恢复这种方式在恢复时间上往往显得力不从心. 本文就总结了几个对于逻辑备份恢复有加速作用的参数和操作 注意:我们的大 ...

  9. Tips12: 私人定制 专属的Unity3D 脚本模板

    在使用U3D的过程中,新建一个C#脚本,它包含着空的Start()和Update()函数.  根据个人习惯的不同,可能有些人有着自己的脚本风格,每次进去都增删改很麻烦,这里介绍一个更改新建脚本模板的方 ...

  10. Scrum 3.2 多鱼点餐系统开发进度(页面优化&下单详细信息页面)

    Scrum 3.2 多鱼点餐系统开发进度(页面优化&下单详细信息页面)  1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选 ...