Full parsing of Android call services

Source: Internet
Author: User

During Android service calling, your program only needs to create an intent object, which contains the requested data and calls startActivity (). The current acitivity is popped up, the previous activity is running.

The activated activity can call the getIntent () method to obtain its intent. Android calls the onNewIntent () method of the acitivity service to transmit other later intents. Note: One activity can be activated by multiple intents at the same time.) an Activity often calls other activities. If the activity needs to return data, you can call the startActivityForResult () method, instead of startActivity ().

For example, an activity calls another activity to allow the user to select an image. Another activity should return the image selected by the user. The result is returned through onActivityResult () of the first activity. The returned form is intent. Service is started by calling Context. startService. Android calls the onStart () method of the service and sends intent to it.

Similarly, intent can use the Context. bindService () method to establish a connection with a running service. The Service obtains the intent using the onBind () method. If the service is not started, bindService () can choose whether to start the service. For example, an activity may want to establish communication with the background music playing service.

In this way, you can use activity to control background playback. Therefore, the activity may call the bindService () method to establish a connection, and then call the interface exposed by the service. The program can call Context. sendBroadcast (), Context. sendOrderedBroadcast (), and Context. sendStickyBroadcast () to pass intent to initialize a broadcast. Broadcast is received through the onReceive () method.

Before Android starts an application, it must know which files are available, so the program must declare all the components used in a manifest file. The declared components will be compiled into the apk file .. The apk file contains the program source code and resources.

Note: It is equivalent to a project file) the packing list is an xml file, and all programs are named AndroidManifest. xml. It also has some other functions, such as specifying the database to be connected and identifying the permissions that the program wants to be granted.

However, the main task of the packing list is to declare the program components to android. Example of a packing list:

 
 
  1. <?xml version="1.0" encoding="utf-8"?> 
  2.  
  3. <manifest . . . > 
  4.  
  5.     <application . . . > 
  6.  
  7.         <activity android:name="com.example.project.FreneticActivity" 
  8.  
  9.                   android:icon="@drawable/small_pic.png" 
  10.  
  11.                   android:label="@string/freneticLabel"   
  12.  
  13.                   . . . > 
  14.  
  15.         </activity> 
  16.  
  17.         . . .  
  18.  
  19. </application> 
  20.  
  21. </manifest> 

<Activity> the node name attribute specifies the Activity class name. icon and label attributes specify the resources used to display the activity. The meaning of another node is similar-<service> is used to declare services, and <receiver ER> is used to declare broadtcast.

Android calls the service declaration content providers. Activities, services. Content providers must be declared and invisible to the system. In addition, broadcast receivers can be declared dynamically without being declared in the packing list.

(See BroadcastReceiver object) use the Context. registerReceiver () method to register with the system. For users, even if the map program is defined in another program and runs in another process, it looks like a part of your program.

Android puts two activities in a single task, so that users can have this experience. The activities are arranged in a stack. The root activity in the stack is the start of the task, or the first activity of the application selected by the user. The activity at the top of the stack is the currently running activity, which is currently attracting user attention.

When an activity starts another activity, the new activity is pushed to the stack and changes to the current activity. The previous activity is still in the task. When the user clicks BACK), the current acitivity is popped up and the previous activity is running.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.