There are four Activity startup modes: standard, singleTop, singleTask, and singleInstance. 1.standard Standard is the default startup mode of Activity. All activities will automatically use this startup mode if no explicit specification is made. Each time you start a new Activity, it is placed at the top of the stack. android:launchMode="standard", each click of the button will create a new Activity Now, let's write a simple button to jump to Activity
Although the page you jump to is the same, a new Activity is created each time you click the button in Task. Activity creates log Startup example diagram 2.singleTop When the startup mode of the Activity is singleTop, and the started Activity is already at the top of the Activity stack, it is used directly. android:launchMode="singleTop" We create NextActivity and add button2 in MainActivity
At this time, if you start MainActivity in MainActivity, it will only be created once in the Activity stack; but if you start NextActivity first and then start MainActivity, a new MainActivity will be created because the top of the Activity stack is NextActivity. MainActivity ->MainActivity ->MainActivity MainActivity -> NextActivity -> MainActivity Startup example diagram 3.singleTask When the launch mode of an activity is singleTask, starting the activity will check whether it already exists in the stack. If it does, all activities above it will be popped out of the stack. android:launchMode="singleTask" Startup example diagram 4.singleInstance In singleInstance mode, there will be a separate back stack to manage activities. No matter which application accesses the activity, they all share the same stack, which allows other programs to call and share the activity. android:launchMode="singleInstance" Startup example diagram The startup process in the figure is: Main -> New -> Next. This process is easy to understand. The return process is: Next -> Main -> New Obviously the order is different, why does this happen? NextActivity and MainActivity are in the same stack. When we return, NextActivity is popped out of the stack. At this time, MainActivity still exists in stack A and is at the top of the stack, so MainActivity is seen. When MainActivity returns, stack A is cleared, and then we see NewActivity on stack B. After that, NewActivity is popped out of the stack, and when stack B is also empty, the App exits. This is a brief introduction to the Activity startup mode. I hope it will be helpful to you. Please correct me if there are any deficiencies or errors. There will be at least one update to this series every week. If you are interested, please follow it. Learn together and improve together. |
<<: Four advantages and five applications of machine learning in the financial field
Why should you be an agent for WeChat Mini Progra...
Judging from the current results, Huawei has buil...
A correct marketing promotion process Marketing pr...
Web information is one of the direct ways that we...
March 15th of every year is Consumer Rights Prote...
Black hat Taobao virtual selling project, a singl...
Have you ever experienced a situation where you h...
The WeChat official website, which has remained u...
For football game fans, September is a month wort...
At the end of 2019, I summarized and reflected on...
Since the African swine fever last year, the coun...
Sister Lin Wei's Secret Love Class: 28 "...
Recently, Apple phones have once again sparked he...
Audit expert: Meng Meng Associate Researcher at t...
The current situation that it is difficult to inc...