current position：Home>Start method of activity
Start method of activity
2022-01-26 23:30:13 【Chen Yuyi】
stay Android in , The jump of the interface is usually by starting different Activity To achieve , So let's talk about that Activity Starting method of .
Explicit call , Literally ” Obvious call “, We can clearly know what we are about to start in the calling method Activity, The specific method of displaying the call is as follows ：
val intent = Intent(this, SecondActivity::class.java) // SecondActivity::class.java amount to Java Medium SecondActivity.class startActivity(intent) Copy code
We need to build a Intent object , The first parameter is passed in this At present Activity The context of , The second object is passed in SecondActivity::class.java As the target Activity, So our intention is obvious , That is, we want to jump to SecondActivity This interface , We just need to call startActivity This function can achieve our goal .
Implicit calls are the opposite of explicit calls , It doesn't specify which... To jump to Activity, But through action, category [ˈkætəɡəri] and data These three filtering information are matched by the system Activity.
by Activity Set filtering information
If we want to start an implicit call Activity, We have to work for this first Activity Set filtering information , Otherwise, this cannot be started through implicit calls Activity Of . Filter information in AndroidMainfest.xml Register in the file Activity Set when , By means of Configuration under the label The content of , You can specify the current Activity Capable of responding to action,category and data.
<activity android:name=".activity.SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="room.join" android:scheme="bjhlliveapp" /> </intent-filter> </activity> Copy code
Start when using implicit call Activity when , Need to match at the same time action,category and data, Otherwise the match fails . One Under the action,category and data There can be multiple , One activity There can be multiple label , As long as the information in any one of them is successfully matched, the matching can be successful .
The following describes the matching rules of various information in detail .
action Is a string ( Case sensitive ) , The system has predefined some for us action, Such as android.intent.action.MAIN etc. , At the same time, we can also define ourselves action, One There can be more than one action.
When we use implicit calls Intent Must specify action, When action and activity Of Any one of action identical ( The value of the string is the same ) when , The match is successful .
category and action The same is a string , At the same time, there are defined in the system category, We can define it ourselves category, But if you want one activity Support implicit call , Then it must be in It is specified in “android.intent.category.DEFAULT” This category.
category The matching rules of action Different , When implicitly called Intent Must specify action, But there can be no category, But if you specify category ( It can be one or more ) , Then all specified category And Medium category identical , Otherwise the match fails .
In popular terms ,category You may not specify ( If it is not specified, it can be matched successfully ) , But once you specify , You have to make sure you specify these category All with what you're about to start activity One of them Medium category identical .
Why not specify, but can match successfully ？ Because I said if activity Support implicit call , Then there must be “android.intent.category.DEFAULT” This category, The system is calling startActivity perhaps startActivityForResult It defaults to Intent add “android.intent. category.DEFAULT” This category, So you can match success .
data The grammatical structure of is as follows ：
<data android:scheme="string" android:host="string" android:port="string" android:path="string" android:pathPattern="string" android:pathPrefix="string" android:mimeType="string" /> Copy code
data It's made up of two parts ,mimeType and URI.mimeType Media type , such as image/jpeg、audio/mpeg4-generic and video/* etc. , Can represent a picture 、 Text 、 Different media formats such as video , and URI It contains more data , Here is URI Structure ：
<scheme>://<host>:<port>/[<path>|<pathPrefix>|<pathPattern>] Copy code
for example ：
content://com.example.project:200/folder/subfolder/etc http://www.baidu.com:80/search/info Copy code
URI The meaning of each data in is as follows ：
- Scheme：URI The pattern of , such as http、file、content etc. , If URI Not specified in scheme, So the whole URI Invalid other parameters for , It also means that URI It's invalid .
- Host：URI The host name , such as www.baidu.com, If host Not specified , So the whole URI Other parameters in are invalid , It also means that URI It's invalid .
- Port：URI Port number in , such as 80, Only when the URI Specified in scheme and host Parameter time port Parameters make sense .
- path、pathPattern and pathPrefix： These three parameters represent path information , among path Represents complete path information ;pathPattern It also represents the complete path information , But it can contain wildcards “”,“” Express 0 Any character or characters , It should be noted that , Due to the specification of regular expressions , If you want to represent a real string , that “*” To write “*”, “\” To write “ \\”;pathPrefix Prefix information representing the path .
data The matching rules are complex , But in general Intent Medium data It has to be with In the same , If There is no , be Intent either , If There is , be Intent Must have tangent and In the same way .
val intent = Intent("android.intent.action.CPW") // intent Constructor specifies action intent.addCategory("android.intent.category.DEFAULT") // addCategory Method specification category intent.setDataAndType(Uri.parse("file://abc"), "text/plain") // setDataAndType Method specification data, Parameter is URI and mimeType startActivity(intent) Copy code
That's about Activity Start the whole content of the method ！
Welcome WeChat search to pay attention to official account. ：Android No worries
Learn more together Android knowledge
author[Chen Yuyi],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
I don't know how to start this
Matlab simulation of transportation optimization algorithm based on PSO
MySQL slow log optimization
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
Popular Linux distributions for embedded computing
Suzhou computer research
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
Implementation time output and greetings of jQuery instance
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
How to save computer research
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command