watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTkzNjE0Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="openActivity"
android:text="开启第二个Activity" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="openSystemActivity"
android:text="开启系统的Activity" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="checkConnection"
android:text="检測网络状态" /> </LinearLayout>

主Activity的代码

package com.examp.manyactivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast; /**
* 案例演示的是显示的激活Activity
*
* @author MartinDong
*
*/
public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} /**
* 用户想要打开第二个界面的时候
*
* @param view
*/
public void openActivity(View view) {
// 创建意图对象
Intent intent = new Intent();
// 方便调用setComponent与一个明白的类名。 // 相当于创建了一个新的组件
// 会话位置|指定要激活的详细的Activity
intent.setClassName(this, "com.examp.manyactivity.SecondActivity");
// 另外一种方式,是在创建意图对象的时候进行指定Activity
// Intent intent2 = new Intent(this, SecondActivity.class); // 激活一个Activity
startActivity(intent);
} /**
* 开启系统中的Activity<br>
* 案例演示的是开启图库的Activity
*
* @param view
*/
public void openSystemActivity(View view) { /*
* 05-31 07:42:44.581: I/ActivityManager(150): START
* {act=android.intent.action.MAIN
* cat=[android.intent.category.LAUNCHER] flg=0x10200000
* cmp=com.android.gallery/com.android.camera.GalleryPicker u=0} from
* pid 282
*/ Intent intent = new Intent();
intent.setClassName("com.android.gallery",
"com.android.camera.GalleryPicker");
startActivity(intent); } /**
* 检測网路状态
*
* @param view
*/
public void checkConnection(View view) {
/*
* 05-31 08:03:01.848: I/ActivityManager(150): START
* {act=android.intent.action.MAIN cmp=com.android.settings/.SubSettings
* (has extras) u=0} from pid 306 因为这里4.0的网络的管理须要传入附加数据,本功能使用2.3的虚拟机<br>
* 05-31 08:05:47.072: I/ActivityManager(61): Starting: Intent {
* act=android.intent.action.MAIN
* cmp=com.android.settings/.WirelessSettings } from pid 168
*/
// 检測网路的连接状态
// 创建连接管理对象
ConnectivityManager cm = (ConnectivityManager) this
.getSystemService(Context.CONNECTIVITY_SERVICE);
// 须要的权限 android.Manifest.permission.ACCESS_NETWORK_STATE
// 获取网络的连接信息
NetworkInfo info = cm.getActiveNetworkInfo();
// 假设没有不论什么的网络信息info为null;
if (info != null && info.isConnected()) {
Toast.makeText(this, "网络可用......", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "网不可用,请设置......", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setClassName("com.android.settings",
"com.android.settings.WirelessSettings");
startActivity(intent);
} }
}

第二个Activity文件:

package com.examp.manyactivity;

import android.app.Activity;
import android.os.Bundle; /**
* 自己定义的Activity<br>
* 必需要继承Activity<br>
* Activity是系统的四大组件之中的一个<br>
* 操作系统想要找到Activity就必须在清单文件AndroidManifest.xml进行注冊<br>
*
*
* @author MartinDong
*
*/
public class SecondActivity extends Activity { /**
* 一般都会重写的方法,用途大都是初始化一些数据,和程序的界面<br>
* Activity创建的时候进行调用
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置显示的布局
setContentView(R.layout.activity_tow); } }

第二个Activity相应的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <RatingBar
android:id="@+id/ratingBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <CheckedTextView
android:id="@+id/checkedTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckedTextView" /> <Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleLarge"
android:layout_width="246dp"
android:layout_height="match_parent" /> </LinearLayout>

清单文件的配置:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examp.manyactivity"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" /> <!-- icon:指定应用程序的图标;label:指定应用程序的名称; -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" > <!-- Activity的注冊 -->
<!-- 假设Activity不进行icon,label的设置,那么将默认的使用应用application的icon,label 的设置 -->
<!-- name指定的是布局文件相应的Activity类 -->
<activity
android:name="com.examp.manyactivity.MainActivity"
android:label="@string/app_name" > <!-- -->
<intent-filter> <!-- 告诉Android的系统这是应用的主界面 -->
<action android:name="android.intent.action.MAIN" />
<!-- 告诉Android的系统创建一个应用图标 -->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.examp.manyactivity.SecondActivity"
android:label="@string/app_name" >
</activity>
</application> </manifest>

注:本案例的网络查看状态仅仅能在2.3的模拟器上使用;

Demo源代码下载:

http://download.csdn.net/detail/u011936142/7429455

Android应用程序中的多个Activity的显示创建和调用的更多相关文章

  1. Android应用程序中Activity的生命周期

    Android应用程序中Activity的生命周期 对于Android来说Activity的生命周期是非常的重要,尤其是对于新学者来说,只有充分了解了Activity的生命周期,才能写出优良用户体验的 ...

  2. 如何在Android应用程序中使用传感器模拟器SensorSimulator

    原文地址; 如何在Android应用程序中使用传感器模拟器 - 移动平台应用软件开发技术 - 博客频道 - CSDN.NET http://blog.csdn.net/pku_android/arti ...

  3. (Android UI)Android应用程序中资源:图片、字符串、颜色、布局等

    Android系统设计采用代码和布局分离的设计模式,因此在设计Android应用程序时需要遵循该设计模式. “把非代码资源(如图片和字符串常量)和代码分离开来始终是一种很好的做法.”---<An ...

  4. Android在程序中浏览网页

    本文是自己学习所做笔记,欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 有时须要在程序中浏览一些网页.当然了能够通过调用系统的浏览器来打开浏览.可是大多 ...

  5. 在 Android 应用程序中使用 SQLite 数据库以及怎么用

    part one : android SQLite 简单介绍 SQLite 介绍 SQLite 一个非常流行的嵌入式数据库.它支持 SQL 语言,而且仅仅利用非常少的内存就有非常好的性能.此外它还是开 ...

  6. 如何在Android应用程序中使用传感器(OpenIntents开源组织SensorSimulator项目)

    原文地址http://blog.sina.com.cn/s/blog_621c16b101013ygl.html OpenIntents项目和可用资源介绍 [1].    项目介绍:OpenInten ...

  7. Android 在一个程序中启动另一个程序

    Android 开发有时需要在一个应用中启动另一个应用,比如Launcher加载所有的已安装的程序的列表,当点击图标时可以启动另一个应用.一般我们知道了另一个应用的包名和MainActivity的名字 ...

  8. Android 在程序中动态添加 View 布局或控件

    有时我们需要在程序中动态添加布局或控件等,下面用程序来展示一下相应的方法: 1.addView 添加View到布局容器 2.removeView 在布局容器中删掉已有的View 3.LayoutPar ...

  9. android在程序中打开另一个程序

    在开发android应用的时候,在一些情况下要有前置条件,比如这边所说的要启动时要确保别的应用程序服务已经打开  或者在操作中启动别的应用等. 先来一段google上的代码: 1. 已知包名和类名的情 ...

随机推荐

  1. Linux下用命令格式化U盘

    1.找到U盘位置(已挂载) sudo fdisk -l 如图,我的在/dev/sdc4 2.格式化U盘 sudo mkfs -t vfat /dev/sdc4 -t 后面是格式化为哪种文件系统格式,v ...

  2. uva 1291(dp)

    题意:有一台跳舞机,中间是0.上左下右分别代表1 2 3 4,初始状态人站在中间.两仅仅脚都踏在0上,然后给出一段序列以0为结束,要按顺序踩出来,从0踏到四个方向须要消耗2点能量,从一个方向到相邻的方 ...

  3. robots.txt网站爬虫文件设置

    目录: 什么是robots.txt robots.txt使用误区 robots.txt使用技巧 什么是robots.txt? robots.txt是搜索引擎中访问网站的时候要查看的第一个文件.Robo ...

  4. IoC容器Autofac之IOC/DI基本概念(二)

    原文:http://www.cnblogs.com/xdp-gacl/p/4249939.html 1.1.IoC是什么 Ioc—Inversion of Control,即“控制反转”,一种设计思想 ...

  5. 推荐几本不错的ASP.NET MVC书

    以前主要是做PHP应用的,由于工作需要,捡起来.NET, 特别是新技术层出不穷,找了几本书看,个人感觉还不错,网上也有电子版的下载 一. ASP.NET MVC4 Web 编程 O'Reilly出版社 ...

  6. Oracle - 使用序列+触发器实现主键自增长

    Oracle中的自增,不如Sql server那般方便. --.创建序列 CREATE SEQUENCE "TABLE_NAME"."SQ_NAME" MINV ...

  7. iOS 证书错误 Certificates下面的 App Store and Ad Hoc是灰的?? 点不了

    原因 因为一个用户名下只能同时有一个发布证书,你之前建立了某个证书并且没有使用的话就无法再创建了,先把它撤销或者使用后才可以继续创建新的

  8. (原)在ubuntu 中安装 swi prolog 和 简单的使用

    参考网址:http://www0.cs.ucl.ac.uk/staff/mahmed/teaching/intro.html 参考网址:http://www.swi-prolog.org/build/ ...

  9. (原)使用mkl计算特征值和特征向量

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5585271.html 参考文档:mkl官方文档 lapack_int LAPACKE_sgeev(in ...

  10. C++ 语言特性的性能分析

    转载:http://www.cnblogs.com/rollenholt/archive/2012/05/07/2487244.html      大多数开发人员通常都有这个观点,即汇编语言和 C 语 ...