可能大家都知道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(安卓)布局之RelativeLayout
  2. android 回调函数二:应用实例
  3. Android(安卓)Studio 创建虚拟机失败 Failed to load 解决办法
  4. 非UI线程可不可以更新UI(一)
  5. Android中Activity的4种加载模式
  6. 使用Android(安卓)Studio 创建第一个Android(安卓)应用
  7. Android(安卓)模拟器创建参数说明
  8. Android(安卓)中创建avd和sdcard
  9. Android开发实例详解之IMF(Android(安卓)SDK Sample—SoftKeyboar

随机推荐

  1. android四大组件--ContentProvider详解
  2. 在android studio中导入cocos2dx中的andr
  3. Android之网络请求4————OkHttp源码1:
  4. Android应用程序资源管理器(Asset Manager
  5. Android将胜过Windows Mobile五大原因
  6. Android(安卓)Java包
  7. 我的android 第31天 - Activity(四)
  8. Android中进程与进程、线程与线程之间如
  9. Android大图片内存清理
  10. 百度地图android sdk拖拽overlay item