activity启动模式之singleTop

一、简介

二、设置方法

在AndroidManifest.xml中将要设置为singleTop启动模式的页面进行配置

<activity android:name="activityLaunchSingleTop.ActivityB2" android:launchMode="singleTop"></activity>

三、代码实例

效果图:

代码:

activityLaunchSingleTop.MainActivity

 package activityLaunchSingleTop;

 import com.example.activityLaunchSingleTop.R;

 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 MainActivity extends Activity{
private Button btn_goB1;//创建一个button对象
private Button btn_goB2;//创建一个button对象
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//父类操作
setContentView(R.layout.activity_main);//引入名为activity_main的界面
btn_goB1=(Button) findViewById(R.id.btn_goB1);//找id为btn_openActivity的button
btn_goB1.setOnClickListener(new OnClickListener() {//设置button点击监听 @Override
public void onClick(View v) {//onclick事件
// TODO Auto-generated method stub
Intent intent=new Intent();//初始化intent
intent.setClass(MainActivity.this,MainActivity.class);//连接
startActivity(intent);//打开activity
}
}); btn_goB2=(Button) findViewById(R.id.btn_goB2);//找id为btn_openActivity的button
btn_goB2.setOnClickListener(new OnClickListener() {//设置button点击监听 @Override
public void onClick(View v) {//onclick事件
// TODO Auto-generated method stub
Intent intent=new Intent();//初始化intent
intent.setClass(MainActivity.this,ActivityB2.class);//连接
startActivity(intent);//打开activity
}
});
}
}

activityLaunchSingleTop.ActivityB2

 package activityLaunchSingleTop;

 import com.example.activityLaunchSingleTop.R;

 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast; public class ActivityB2 extends Activity{
private Button btn_goB1;//创建一个button对象
private Button btn_goB2;//创建一个button对象
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//父类操作
setContentView(R.layout.activity_b2);//引入名为activity_main的界面
btn_goB1=(Button) findViewById(R.id.btn_goB1);//找id为btn_openActivity的button
btn_goB1.setOnClickListener(new OnClickListener() {//设置button点击监听 @Override
public void onClick(View v) {//onclick事件
// TODO Auto-generated method stub
Intent intent=new Intent();//初始化intent
intent.setClass(ActivityB2.this,MainActivity.class);//连接
startActivity(intent);//打开activity
}
}); btn_goB2=(Button) findViewById(R.id.btn_goB2);//找id为btn_openActivity的button
btn_goB2.setOnClickListener(new OnClickListener() {//设置button点击监听 @Override
public void onClick(View v) {//onclick事件
// TODO Auto-generated method stub
Intent intent=new Intent();//初始化intent
intent.setClass(ActivityB2.this,ActivityB2.class);//连接
startActivity(intent);//打开activity
}
});
}
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
Toast.makeText(this, "onNewIntent", Toast.LENGTH_SHORT).show();;
}
}

/activityLaunchSingleTop/AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activityLaunchSingleTop"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="activityLaunchSingleTop.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <activity android:name="activityLaunchSingleTop.ActivityB2" android:launchMode="singleTop"></activity>
</application> </manifest>

/activityLaunchSingleTop/res/layout/activity_main.xml

 <?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" > <TextView
android:id="@+id/tV_B1"
android:layout_width="match_parent"
android:layout_height="96dp"
android:text="@string/tV_B1"
android:textAppearance="?android:attr/textAppearanceLarge" /> <Button
android:id="@+id/btn_goB1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.00"
android:text="@string/btn_goB1" /> <Button
android:id="@+id/btn_goB2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_goB2" /> </LinearLayout>

/activityLaunchSingleTop/res/layout/activity_b2.xml

 <?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" > <TextView
android:id="@+id/tV_B2"
android:layout_width="match_parent"
android:layout_height="96dp"
android:text="@string/tV_B2"
android:textAppearance="?android:attr/textAppearanceLarge" /> <Button
android:id="@+id/btn_goB1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.00"
android:text="@string/btn_goB1" /> <Button
android:id="@+id/btn_goB2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_goB2" /> </LinearLayout>

activity启动模式之singleTop的更多相关文章

  1. Activity启动模式

    ------siwuxie095 共4种启动模式:standard singleTop singleTask singleInstance 1.标准启动模式(standard) 也即默认的启动模式 ( ...

  2. Android Activity 启动模式和任务栈

    在了解了基本的Activity的生命周期后,我们能够很好的在一个Activity上面做相关的业务.但是这是不够的,因为Android通过任务栈来保存整个APP的Activity,合理的调度任务栈才能够 ...

  3. 深入Activity,Activity启动模式LaunchMode完全解析

    转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53221384本文出自[DylanAndroid的博客] 在平时的开发中,我们可 ...

  4. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  5. 【转】Activity启动模式 及 Intent Flags 与 栈 的关联分析

    http://blog.csdn.net/vipzjyno1/article/details/25463457    在学习Android的过程中,Intent是我们最常用Android用于进程内或进 ...

  6. Android中Activity启动模式详解

    在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...

  7. Activity启动模式图文详解

    转载自:http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0520/2897.html  英文原文:Understand Android A ...

  8. Android-3 Activity启动模式

    Activity启动模式 android:launchMode="singleTask" * Standard 每次都创建一个新实例 -- TaskID不变,ActivityID改 ...

  9. Android Activity 启动模式详解

    最近有群里的朋友问我 Activity的四种启动模式分别是什么意思? 当初因为项目比较忙,草草的解释了下, Api文档中说的也只是一般,在这里就小记一下吧,以便有更多的朋友对Activity启动模式了 ...

随机推荐

  1. filezilla 读取目录失败

    用到FTP,本来一直用主动模式,可以最近老是读取目录失败,425 Can't open data connection 和 读取目录列表失败(搞了好久,一天) 问题解决 这个问题主要是由于使用Pass ...

  2. mysql 数据库表名大小写问题

    lower_case_table_names=1 原来Linux下的MySQL默认是区分表名大小写的,通过如下设置,可以让MySQL不区分表名大小写:1.用root登录,修改 /usr/my.cnf: ...

  3. python迭代器、生成器、yield和xrange

    https://blog.csdn.net/u010138758/article/details/56291013

  4. mysql聚合函数操作

    1.mysql对中文进行排序 注:是用convert函数用gb2312编码转换 SELECT * FROM 表名 ORDER BY CONVERT(字段名 USING gb2312 ) ASC;

  5. 使用Stanford Parser进行句法分析

    一.句法分析 1.定义 句法分析判断输入的单词序列(一般为句子)的构成是否合乎给定的语法,并通过构造句法树来确定句子的结构以及各层次句法成分之间的关系,即确定一个句子中的哪些词构成一个短语,哪些词是动 ...

  6. 【算法题12 解码方法decode way】

    1.来源LeetCode91 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请 ...

  7. Chrome调试模式获取App混合应用H5界面元素

    原文章地址http://blog.csdn.net/qq_19636353/article/details/53731254 浏览器的远程调试工具,使得我们可以通过PC上开启的控制台,调试手机浏览器中 ...

  8. nginx限制连接

    limit_conn_zone $binary_remote_addr zone=addr:10m; locaton /download { limit_rate_after 128k; #是对每个连 ...

  9. mysql第二天作业

    create database 数据库名 default charset utf8;use 数据库名;1.创建成绩表,字段包括:学生姓名,语文成绩,数学成绩,英语成绩create table resu ...

  10. Spring框架学习之IOC(二)

    Spring框架学习之IOC(二) 接着上一篇的内容,下面开始IOC基于注解装配相关的内容 在 classpath 中扫描组件 <context:component-scan> 特定组件包 ...