当前位置:网站首页>Andorid development art exploration notes (2), cross platform applet development framework

Andorid development art exploration notes (2), cross platform applet development framework

2022-06-24 00:06:00 Ordinary netizens

  1. singleTop: Stack top reuse mode

In this mode, if Activity Already at the top of the stack, this Activity Will not recreate , At the same time, its onNewIntent Method will be called , Through the parameters of this method, we can get the current request information . If the new Activity Not at the top of the stack , Then it will be recreated . If the current stack is ABCD, The model is standard, To create a D, The stack becomes ABCDD, If singleTop Then for ABCD.

  1. singleTask: In stack reuse mode

This is a single instance mode .Activity When starting, first find out whether there is an instance in the stack , If so, set it to the top of the stack , Do not create a new instance , If it does not exist, create a new instance and push it onto the stack .

①S1 In the stack Activity by ABC, Want to start D, Then create an instance stack ,S1 Turn into ABCD.

②S1 In the stack ABC, but D The desired stack is S2,S2 non-existent , therefore S2 and D At the same time, create and transfer D Push the S2 In the stack .

③S1 In the stack ABCD, Want to be in S1 Start in B, Will CD Out of the stack ,S1 The stack becomes AB.

( All the above are in singTask In mode )

  1. singleInstance: Single instance mode .

It's a kind of reinforcement singleTask Pattern , So it has singleTask The function of mode , A little bit stronger , That's the pattern Activity It can only be located on one task stack .Activity A In this mode, it can only be located on the stack S1 in ,Activity B Can only be located separately on the stack S2 in .

< About TaskAffinity>

It marks a Activity The name of the required task stack . By default, it's all Activity The package name of the app . So it's connected to singleTask Pairs using . One more parameter allowTaskReparenting, If it is True also singleTask Next , that When one Activity A start-up B One of them Activity, When B Startup time , This Activity Your task stack will start from A Transfer to B.

You can do this by Menifest Start mode is specified in , You can also get it from Acitivity Of addFlags Set the flag bit to specify the startup mode . In terms of priority , The latter is higher than the former . And the limited scope of the two methods is also different , The former cannot be specified FLAG_ACTIVITY_CLEAR_TOP identification , The latter cannot be Activity Appoint singleInstance Pattern .

In the book is singleTask An example is introduced to illustrate its operation :

A by standard Pattern , So its TaskAffinity Is the default package name S1,B and C Are all singleTask Pattern ,TaskAffinity by S2.A Start... First B,B Then start C, At this time, the stack is :S1 There are only A, because B and C need S2 Task stack , therefore B Created S2 Stack ,S2 In the stack BC. then C start-up A, This time because A yes standard Pattern , So it will go to the one that created it Actvitiy namely C In the stack of , therefore S2 Stack becomes BCA,S1 Stack as A. next A start-up B, because B by singleTask Pattern , therefore S2 Medium CA All pop up the stack to let B To the top of the stack , here S2 Stack as B. Then press the back key ,S2 Stack Actviity Be taken out , Backstage S1 The stack is put into the foreground . and S1 Only A, But this A Not at all S2 Stack but S1 Stack . next A Press the return key in the , Of all stacks Activity Be taken out , Back to the desktop .

Here are some examples singleTask To understand the task stack diagram :

《Android Summary of learning notes + Latest mobile architecture video + Big Android interview questions + Project actual combat source code handout 》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 Full content open source sharing

 Picture description here

 Picture description here

< About Activity Of Flags>

  • FLAG_ACTIVITY_NEW_TASK

Designated as singleTask Pattern

原网站

版权声明
本文为[Ordinary netizens]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206232147195197.html