In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to use Intent in Android. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Intent Chinese meaning: intention
Intent is the bridge between components, which is very important in Android.
There are three types of Inten that can be started: Activity (interface), Service (service), and Broadcasts (broadcast).
Startup interface: StartActivity (), StartActivityForResult ()
Start the service: StartService (), BindService ()
Send broadcast: SendBroadcasts ()
Intent can be divided into explicit intention and implicit intention.
Explicit intent: the open component needs to be clearly specified
Implicit intention: there is no clear indication of the open component
The attributes of intention are:
Show intention: component
Hermit intention: action,category,data, type, extras,flags
Intent mainly has the following four important attributes, which are:
The value of the Action:Action property is a string that represents a series of common actions that have been defined in the system. Set it through the setAction () method or in the manifest file AndroidManifest.xml. The default is DEFAULT.
Data:Data is usually operational data defined in URI format. For example: tel://. Set through the setData () method.
The Category:Category property is used to specify the environment in which the current action (Action) is performed. Set it through the addCategory () method or in the manifest file AndroidManifest.xml. The default is CATEGORY_DEFAULT.
The Extras:Extras attribute is primarily used to pass additional data needed by the target component. Set through the putExtras () method.
Action: action-the action to be completed by Intent-the type required is: string
/ / sample code is as follows: Intent intent = new Intent (); intent.setAction ("com.cpc.www"); startActivity (intent)
Additional information for Category:Action actions
Use a filter to specify the type of IntentFilter receive
Only when all the Category in the Intent request exactly matches one of the IntentFilter in the component will the Intent request be allowed to pass the test, and the redundant declaration in the IntentFilter will not cause the match to fail.
Flags:
1) standard: default mode. When you want to start the current interface, you will create a new stack, manage Activity, and add a new Activity instance to the stack.
2) singleTop: single instance at the top of the stack
a. Create a new Activity object if the target interface is in the stack
b. If the target interface is at the top of the stack, no new Activity object will be created
3) singleTask: single instance in the stack
a. Create a new Activity object if the target interface does not exist in the stack
b. If the target interface already exists in the stack, clear the previous Acticity in the stack and put the target interface on the top of the stack
4) singleInstance: global single instance
Note: set an Activity singleInstance. At this point, if you need to load Activity, you will create another stack to manage the Activity.
a. If there is no Acticity in the stack, create a new Activity object
b. If Activity already exists in the stack, move the existing Acticity to the top of the stack
Flags
Intent.FLAG_ACTIVITY_NEW_TASK is similar to standard
Intent.FLAG_ACTIVITY_CLEAR_TOP is similar to singleTask
Intent.FLAG_ACTIVITY_SINGLE_TOP is similar to singleTop
These are all the contents of the article "how to use Intent in Android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.