Android Service Summary

Source: Internet
Author: User

2. Service
2-1: Start the service
2-1-1: Create a service
Extends Service
2-1-2: Register
<service android:name= "Com.firefly.style_study. MyService "></service>
2-2: Binding Service
Process ideas: First use the media binding service, to use "play", "pause" and other functions
2-2-1: First use serviceconnection as the medium, bind the service
Serviceconnection Conn;
2-2-2: Create a binder to inherit binder (implemented IBinder interface)
public class Mybinder extends Binder {
MyService GetService () {
return myservice.this;
}
}
2-2-3: Return your newly created binder in the default IBinder method
@Override
Public IBinder Onbind (Intent Intent) {
return new Mybinder ();
}
2-2-4: Instantiate a service that you write in a method of binding success
MyService MS;
conn= New Serviceconnection () {
@Override
public void onservicedisconnected (componentname name) {
LOG.E ("TAG", "binding cancellation");
}
@Override
public void onserviceconnected (componentname name, IBinder service) {
This method is executed when the binding is successful
LOG.E ("TAG", "bind succeeded");
Mybinder Binde = (mybinder) service;
ms = Binde.getservice ();

}
};
2-2-5: Start binding
Bindservice (i3, Conn, bind_auto_create);
2-2-6: Play, pause music
Ms. Playmusic ();
Ms. Stopmusic ();
2-2-7: Unbind
Unbindservice (conn);

Android Service Summary

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.