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. debian各种包

    1 zlib compression library sudo apt-get install zlib1g-dev 2 c-ares库 libc-ares-dev - asynchronous na ...

  2. mysql 中 select中 用case

    将 countertype 整数类型转成字符串类型 SELECT counterType, CASE counterType WHEN 1 THEN 'CTP'WHEN 2 THEN 'NULL'WH ...

  3. 高性能网站服务器的架设优化-Nginx优化

    一:对于高性能网站 ,请求量大,如何支撑?思路 在网站架构设计中,大家一定对 LNMP (Linux Nginx Mysql Php) 不陌生.LNMP 确实是一个非常优秀的架构,秉承着自由,开放,高 ...

  4. Design Pattern – Proxy, Adapter, Facade, Mediator

    这几个模式比较类似, 都是用作interface, 但有所不同 Proxy, 特点是以假乱真, client在使用的时候就和在使用真正的object一样, 接口完全一致, proxy和object的交 ...

  5. 理解Python的双下划线命名

    引子 我热情地邀请大家猜测下面这段程序的输出: class A(object):        def __init__(self):               self.__private()   ...

  6. 聊聊 Java 中日期的几种常见操作 —— 取值、转换、加减、比较

    Java 的开发过程中免不了与 Date 类型纠缠,准备总结一下项目经常使用的日期相关操作,JDK 版本 1.7,如果能够帮助大家节约那么几分钟起身活动一下,去泡杯咖啡,便是极好的,嘿嘿.当然,我只提 ...

  7. Vue中动态添加多个class

    vue中可以通过 :class=""这样来根据一定的条件来动态添加class,但是有时候需要判断的条件比较多,需要动态添加的class也比较多,这个时候其实也很简单 先看一下示例: ...

  8. django-应用中和amdin使用富文本编辑器kindeditor

    文章描述.新闻详情和产品介绍等,都需要大量的文字描述信息或图片.视频.文字的编辑等,这个时候我们就需要介绍第三方富文本编辑器. 今天介绍的是django中绑定和应用kindeditor编辑器: 效果如 ...

  9. 查询前几条记录 top limit

    SQL Server 数据库中的Top关键字可实现查询数据库表中的前几条数据,但是需要注意的是,Top关键字只能在SQL Server数据库中可以使用,而在MySQL数据库中就要使用具有同样功能的LI ...

  10. 单例模式及getInstance()的用法

    一般在单例模式下使用.getInstance()创建对象:但并不是所有有私有构造方法,对外通过getInstance方法提供 实例的情况就是单例模式. 注:单例模式:一个类有且只有一个实例.1,一个私 ...