新说android launch mode

可能大家都知道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 its onNewIntent() 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 is not an 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 its onNewIntent() 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是不同的概念,别搞混了


转载于:https://my.oschina.net/u/1175512/blog/402008

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值