An Android application usually consists of the following four components:
-
Activity
-
Intent Receiver
-
Service
-
Content Provider
Not every app has all four of these, and your app may only use some of them.
Once you decide which components your app should include, you need to list them in the AndroidManifest.xml file. This is an XML file that contains the components defined by your app, their functions, and their prerequisites. You can visit
the Android manifest online documentation
for a detailed description of this file.
Activity
Note: Proper nouns are not translated.
Activities are the most commonly used of the four components. In a program, an Activity is usually presented as a separate interface (screen). Each Aactivity is a separate class that extends and implements the Activity base class. This class displays a user interface composed of Views and responds to events. Most programs have multiple Activities. For example, a text messaging program has several interfaces: a contact list interface, a message writing interface, a message viewing interface, or a settings interface. Each interface is an Activity. Switching to another interface is loading a new Activity. In some cases, an Activity may return a value to the previous Activity - for example, an Activity that allows the user to select a photo will return the selected photo to its caller.
When a new screen is opened, the previous screen is paused and put into the history stack (screen switching history stack). Users can go back to the previously opened screens stored in the history stack. Screens with no screen value can also be deleted from the history stack. Android keeps all screens generated by the program running in the history stack: from the first screen to the last one.
Intents and Intent Filters
Android uses a special Intent class to switch interfaces. Intent describes what the program wants to do (intent, n. intention, purpose, intention). The two most important parts of the data structure are the action and the data processed according to established rules. Typical actions are MAIN (the entrance to the Activity), VIEW, PICK, EDIT, and so on. Data is represented by a URI. For example, to view someone's contact information, you need to create an Intent, use the VIEW action, and the data is a URI pointing to the person.
There is a related class called IntentFilter . An Intent is a request to do something; an IntentFilter describes what intents an Activity (or IntentReceiver below) can handle. An Activity that displays a person's contact information uses an IntentFilter, which means it knows how to handle VIEW operations that apply to that person's data. Activities use IntentFilters in the AndroidManifest.xml file.
Activity switching is done by parsing Intents. Use startActivity(myIntent) to start a new Activity. The system examines all installed programs' IntentFilters and finds the Activity that best matches myIntent. The new Activity receives the message from the Intent and is therefore started. The process of parsing Intents occurs when startActivity is called in real time, which has two benefits:
-
Activities can reuse the functionality of other components by issuing only one Intent request
-
Activities can be replaced at any time with a new Activity with an equivalent IntentFilter
Intent Receiver
When you want to execute some code related to external events, such as when a call rings, when the data network is available, or do something in the middle of the night, you may need to use an IntentReceiver . IntentReceivers have no UI, although they use NotificationManager to notify the user that something interesting has happened. IntentReceivers are declared in the AndroidManifest.xml file, but you can declare them using Context.registerReceiver() . Your program does not have to be running to wait for IntentReceivers to be called. When an IntentReceiver is triggered, the system will naturally start your program if necessary. Programs can also send their own Intent broadcasts to other programs through Context.broadcastIntent() .
Service
A service is a piece of code that has no UI and is always present in the system. The best example is a media player that plays songs from a playlist. In a media player application, there might be one or more activities that let the user select songs to play. However, playing songs in the background doesn't require any intervention from the activity, because the user wants to be able to switch to other interfaces while the music is playing. In this case, the media player activity needs to start a service with Context.startService() , which runs in the background to keep the music playing. The system keeps the background music playing service running until the media player is closed. ( Life Cycle of an Android Application provides more information about services.) Note that you can connect to a service (and start it if it's not already running) with the Context.bindService() method. Once connected, you can talk to the service through the interface provided by the service. For the music service, this provides functions such as pause and replay.
Content Provider
The application stores data in a SQLite database format file or in other valid devices. If you want other programs to be able to use your own program's data, Content Provider is very useful. Content Provider is a class that implements a series of standard methods. This class enables other programs to store and read data that can be processed by a certain Content Provider. For more information about Content Provider, please see Accessing Content Providers .
Previous article:The application of GSM Modem measurement and control under WinCE system
Next article:Design of Embedded Network Server
- Popular Resources
- Popular amplifiers
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Problems with drawing curves on testing machines
- Analysis of electromagnetic compatibility issues in power supply internal systems
- LCD1602 display program based on stm32
- What are the advantages of PHY6212 that can support Bluetooth Mesh networking (I)
- Not just nostalgia - a complete collection of radio principles, circuits, repairs and assembly information
- Is there any material that can block the bass and let the treble through?
- The upcoming TinyPICO micro ESP32 development board
- About STM32F103C8T6 using ST-Link's SWD download No Target Connected solution
- Perfect replacement - BLDC three-phase brushless pre-driver--MS4931 A4931
- Effects of Differential Input Clamping on Operational Amplifiers