SingleTask和SingleInstance详解

           SingleTask(FLAG_ACTIVITY_NEW_TASK):  

          

            

        如图,有两个Application A 和 B。其中B中的activity b为SingleTask。首先启动B,在activity a中调用b,b又调用c。然后按Home键返回桌面。打开APP A。在Activity x中调用b。这时b的taskid和a的一样。说明系统没用重新创建Task和b的实例,而是直接调用TaskB中已经存在的b。但是TaskB中的activity c已经被Destroy掉。只有b和a了。b在栈顶。

       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.


          SingleInstance:


        如图,B中的activity b为SingleInstance模式。打开B程序,在a中调用b,此时b的taskId和a的不一样,说明系统为b创建了一个新的task并实例化b。在b中调用c时,c的taskId和a一致。(当在c中依次按下返回键时,先返回到a,然后再返回到b,最后返回到桌面。)然后当按下Home键,打开A程序,然后再x中调用b时,系统不会再去创建b的实例,而是使用已经存在的b的实例。

         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.

        singleInstance模式只会创建一个Task,并且这个Task中只存在一个Activity。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值