Android Core Component Service (2)

Source: Internet
Author: User
Tags call back

The second is to start the Service by binding it. First look at the flowchart.

Click to view the chart

The biggest difference between the binding method and the method described in section 1 is that an Activity can be associated with a Service. When the associated Activity ends, the corresponding Service also stops, at the same time, in the bound Activity, we can also call back the methods we have defined in the Service. Here we use this. bindService (intent, myServiceConnection, Context. BIND_AUTO_CREATE); to start the Service. After the Service is created and bound to the Activity, it calls back the ServiceConnection () defined by us and returns the IBinder interface. Then, we can call the methods in the Service. At this time, the Activity is bound to the Service, and the Activity exits after exiting the Service. The Service statement is as follows. intent filter is used to filter the received Service.

 
 
  1. <service android:enabled="true" android:name=".service.mediaplayer.BindMusicService"> 
  2. <intent-filter> 
  3. <action android:name="com.androidtest.service.mediaplayer.BindMusicService" /> 
  4. </intent-filter> 
  5. </service>  

The source code for this section can be downloaded here: http://down.51cto.com/data/326385

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.