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. MyBatis 映射文件详解

    1. MyBatis 映射文件之<select>标签 <select>用来定义查询操作; "id": 唯一标识符,需要和接口中的方法名一致; paramet ...

  2. JS改变HTML元素的绝对坐标

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DT ...

  3. 手动拼写出来的sp_who结果集

    SELECT SPID = er.session_id  ,STATUS = ses.STATUS  ,[Login] = ses.login_name  ,Host = ses.host_name  ...

  4. 让你的代码量减少3倍!使用kotlin开发Android

    (一) 创建Kotlin工程 (二) –秘笈!扩展函数 (三) 缩短五倍的Java Bean 本项目使用的代码地址

  5. Hadoop2.0NameNode HA和Federation实践

    一.背景 天云趋势在2012年下半年开始为某大型国有银行的历史交易数据备份及查询提供基于Hadoop的技术解决方案,由于行业的特殊性,客户对服务的可 用性有着非常高的要求,而HDFS长久以来都被单点故 ...

  6. java反射基础知识(二)

    1. 了解 Java 中的反射 1.1 什么是 Java 的反射 Java 反射是可以让我们在运行时获取类的函数.属性.父类.接口等 Class 内部信息的机制.通过反射还可以让我们在运行期实例化对象 ...

  7. mysql双向主从同步

    双向主从同步 双方互相主从同步配置 然后再my.cnf中加上如下配置 [mysqld]master1:auto_increment_increment = 2 //自增ID的间隔,如1 3 5间隔为2 ...

  8. xpath(待补充)

    from lxml import etree html=""" <div> <ul> <li>1</li> <li ...

  9. Getting Started with Rails (1)

    按照官网http://guides.rubyonrails.org/getting_started.html上学习了一下例子.在过程中有很多刚开始没理解的地方,写下来. 首先,建立了一个resourc ...

  10. oracle 任务使用

    文章访问地址:http://www.cnblogs.com/hoojo/p/oracle_procedure_job_interval.html