配置:

在AndroidManifest.xml中找到<activity/>并在里面配上android:launchMode="启动模式"

如:

<activity android:name="com.njupt.luanchmode.Main2Activity" android:label="B界面"android:launchMode="singleInstance"/>


常见类型(个人理解):

1)standard:不改变操作序列 .什么叫操作序列,例如你先进入A,在进入B,接着又进入A,最后又进入B。

那么你的操作序列就是A ----- >> B ------ >> A -------->>B。所以退出时的顺序就是反过来以后的结果

B------->>A------->>B------->>A

2)singleTop:合并相邻的重复项

3)singleTask:合并重复项

4)singleInstance:始终只保留最新的那一个


原理图:

1)standard:


2)singleTop


3)singleTask


4)singleInsatnce




实现如下:

1、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:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="A界面"        />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="打开A界面"        android:onClick="open1"        />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="打开B界面"        android:onClick="open2"        /></LinearLayout>


2、MainActivity

package com.njupt.luanchmode;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}public void open1(View v){Intent intent = new Intent(this,MainActivity.class);startActivity(intent);}public void open2(View v){Intent intent = new Intent(this,Main2Activity.class);startActivity(intent);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}


3、main2.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:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="B界面"        />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="打开A界面"        android:onClick="open1"        />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="打开B界面"        android:onClick="open2"        /></LinearLayout>


4、Main2Activity

package com.njupt.luanchmode;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;public class Main2Activity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);    setContentView(R.layout.main2);}public void open1(View v){Intent intent = new Intent(this,MainActivity.class);startActivity(intent);}public void open2(View v){Intent intent = new Intent(this,Main2Activity.class);startActivity(intent);}}


更多相关文章

  1. 打开Android(安卓)Studio报错"required plugin “Android(安卓)S
  2. Android(安卓)实现在Java代码中修改UI界面,并修改界面
  3. Android(安卓)EditText取消自动焦点获取
  4. android 开发收银系统,弹出键盘固定界面UI的方法
  5. android 判断网络时打开设置
  6. Android学习中遇到的问题及解决方案
  7. Android中自动跳转到系统设置界面
  8. Android(安卓)9.0及以上WebView无法打开网页 ERR_CLEARTEXT_NOT_
  9. Android中界面实现全屏显示的两种方式

随机推荐

  1. Manage Android source code like source
  2. Android下获取设备唯一标识(UDID, Device
  3. Android 面试题之基础(不断更新)
  4. Android碰到的问题之一
  5. 隐藏的数字咪咪
  6. android 抖动原理
  7. android利用Handler开启线程和关闭线程
  8. Android(安卓)定制RadioButton样式
  9. Android(安卓)文件下载三种基本方式
  10. as android 打包