activity启动模式之singleTop
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的更多相关文章
- Activity启动模式
------siwuxie095 共4种启动模式:standard singleTop singleTask singleInstance 1.标准启动模式(standard) 也即默认的启动模式 ( ...
- Android Activity 启动模式和任务栈
在了解了基本的Activity的生命周期后,我们能够很好的在一个Activity上面做相关的业务.但是这是不够的,因为Android通过任务栈来保存整个APP的Activity,合理的调度任务栈才能够 ...
- 深入Activity,Activity启动模式LaunchMode完全解析
转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53221384本文出自[DylanAndroid的博客] 在平时的开发中,我们可 ...
- Activity启动模式 及 Intent Flags 与 栈 的关联分析
http://blog.csdn.net/vipzjyno1/article/details/25463457 Android启动模式Flags栈Task 目录(?)[+] 什么是栈 栈 ...
- 【转】Activity启动模式 及 Intent Flags 与 栈 的关联分析
http://blog.csdn.net/vipzjyno1/article/details/25463457 在学习Android的过程中,Intent是我们最常用Android用于进程内或进 ...
- Android中Activity启动模式详解
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...
- Activity启动模式图文详解
转载自:http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0520/2897.html 英文原文:Understand Android A ...
- Android-3 Activity启动模式
Activity启动模式 android:launchMode="singleTask" * Standard 每次都创建一个新实例 -- TaskID不变,ActivityID改 ...
- Android Activity 启动模式详解
最近有群里的朋友问我 Activity的四种启动模式分别是什么意思? 当初因为项目比较忙,草草的解释了下, Api文档中说的也只是一般,在这里就小记一下吧,以便有更多的朋友对Activity启动模式了 ...
随机推荐
- Redis 教程
http://www.runoob.com/redis/redis-tutorial.html Redis系列(一)--安装.helloworld以及读懂配置文件 再开个redis系列,本系列打算不详 ...
- php 正则表达式三.模式修正
1.贪婪模式和懒惰模式, 贪婪模式:php中正则默认是贪婪模式,匹配尽可能多 的字符,比如 $pattern='/a+b/'; $subject='aaaaaaaaab,那么可能会preg_match ...
- python pip源配置,pip配置文件存放位置
https://blog.csdn.net/u013066730/article/details/54580789/ pip源配置文件可以放置的位置: Linux/Unix: /etc/pip.con ...
- centos7在vmware上无法上网
centos7在虚拟机中设置NAT后也无法上网! 首先激活网卡!打开桌面右键在终端中打开:cd /etc/sysconfig/network-scripts/ls 找到以ifcfg开头的,如ifcfg ...
- LinkedList 的get方法分析---java
Java LinkedList.get() 获取元素 Get(int)方法的实现在remove(int)中已经涉及过了.首先判断位置信息是否合法(大于等于0,小于当前LinkedList实例的Si ...
- 汇编学习笔记(AT&T语法)
一个最基本的汇编程序如下所示: .section .data .section .text .globl _start _start: movl $, %eax # the number 1 is t ...
- django中的setting全局变量的导入
需求:在py文件中导入settings.py中的变量BASE_DIR settings.py文件 import os # Build paths inside the project like thi ...
- golang strings.Split的疑问
先看下面的代码 func main() { fmt.Println("Hello, 世界") cc:=[...]int{} b:="" a:=strings.S ...
- IOS中快速集成短信SDK验证开发(SMSSDK),IOS开发中如何设置手机验证码
[转载请注明出处] sdk是别人的,我只是下载来集成一下. smssdk下载网站:http://www.mob.com/(也有其他很多网站有类似SDK,譬如https://www.juhe.cn/等等 ...
- Linux用户、群组及权限
由于对文件的操作需要切换到相应文件夹下进行,所以对文件内容的修改,最基本的是需要其文件夹执行的权限. 文件夹的读权限(read)可以独立行使,但是对文件夹内容的写权限(对其内文件的新建.删除.重命名) ...