当前位置:网站首页>Four startup modes of Activity

Four startup modes of Activity

2022-08-11 07:51:00 is a small A

One.standard:

The default startup mode of the system, stack structure, first in, last out, open an activity and push it into the stack, then open the next activity, and then push into the stack. The activities we usually create directly are all activities in this mode

The characteristics of Activity in this mode are: as long as you create an Activity instance, once the Activity is activated, the newly created instance will be added to the task stack, and if you exit the Activity, the instance will be destroyed in the task stack.

two.singleTop:

If an Activity activates itself, that is, the top of the task stack is the Activity, it does not need to be created, and an Activity instance must be created in other cases;

Three.singleTask:

If the instance of the Activity to be activated exists in the task stack, you don't need to create it. You only need to put the Activity on the top of the stack, and pop all Activity instances above the Activity;

four.singleInstance:

If we set an activity to this singleStance startup mode, then when the activity is activated, it will be placed on a separate stack, and the next time it is used, the stack will be used directly. For example, the calling application is started in a singleStance mode.activity

There are two ways to implement the code

The first one configures the desired startup mode in AndroidMainfest

The second configuration is in Java code

 Intent intent = new Intent(MainActivity.this,SecondActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);// do logic processing herestartActivity(intent);

原网站

版权声明
本文为[is a small A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110644322785.html