可能大家都知道android有4种launch mode分别是:

  1. standard

  2. singleTop

  3. singleTask

  4. singleInstance

很多中文博客中解释的不是那么清楚而且不是那么准确,今天抽空总结一下android的原文说法

  • standard

Default. The system creates a new instance of the activity in the task from which it was started and routes the intent to it. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances.

默认的模式。每次访问此类标识的activity都会在task中创建一个实例。可以在不同的多个task中被多次创建,一个task中可以有多个实例。

总结:没有任何限制的new

  • singleTop

If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to itsonNewIntent()method, rather than creating a new instance of the activity. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances (but only if the activity at the top of the back stack isnotan existing instance of the activity).

顶部单例模式。如果task的顶部是此类标识的activity,那么再次访问该activity时不会创建实例,只会请求一次 onNewIntent方法。除此条件之外,和standard没有区别。

  • singleTask

The system creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to itsonNewIntent()method, rather than creating a new instance. Only one instance of the activity can exist at a time.

底部单例模式。如果是此类标识的activity,那么该activity一定是在一个task底部的,没有其他情况。当task中没有此类activity时,系统会创建一个新的task以供该activity实例化,如果已经创建了新的task并且该activity是栈底位置,那么会调用该activity的onNewIntent方法而不会创建实例,这种activity在同一时间只能有一个实例。

  • singleInstance

Same as"singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task; any activities started by this one open in a separate task.

单例模式。如果是此类标识的activity,创建时系统会新建一个task,并且不会往这个task中加入其他的activity,供该activity独享。和singeTask的区别是singeTask的task中还能加入其他activity,而它,只能是独孤求败。。。


顺便说一句:back stack跟task是不同的概念,别搞混了


更多相关文章

  1. Android中Activity的4种加载模式
  2. Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)
  3. Android开发手记一 NDK编程实例
  4. Android 当中的 MVP 模式(二)封装
  5. android沉浸状态栏实现、地图多线路规划、Retrofit+RxJava+Jsoup
  6. Android中的Shape和Selector的结合使用实例

随机推荐

  1. Android(安卓)自动换行流式布局的RadioGr
  2. android典型代码系列(十)------获取一个
  3. Android中常用的函数
  4. Different ways to access HTTP resource
  5. android 图片点击一下就放大到全屏,再点
  6. android OS Service
  7. 捕获Android文本输入框的软键盘完成(Done
  8. ANDROID图片压缩代码
  9. Android在onCreate()中获得控件尺寸
  10. android 开源项目列表