Broadcast and Service Summary 2

Source: Internet
Author: User

1. Two ways to start service

StartService Start-the process in which the service is located becomes a service process, and it is not related to the activity that initiates it. Cannot invoke methods in the service--Life cycle: OnCreate ()-Onstartcommand ()-OnDestroy ()Bindservice Start-The process priority does not change, the original is what is how, can not do the background run, easy to be killed. Binding services and activity are die, the activity is destroyed, the service is destroyed, but the service is destroyed, the activity will not be destroyed. Can invoke methods in the service--Life cycle: onCreate---onbind----Onunbind OnDestroy2, the process of certification program implementation (that is, how to invoke the service method)<1> Create a service and configure it in the manifest file<2> Create an intermediate inner class that inherits the binder (the implementation class of the IBinder interface) and calls the methods in the service in this class<3> returns this IBinder object, which is the Middleman object<4> in activity, get the object in the Onservicedisconnected () method3, can also write a variety of methods in the interface4. External class. This.play () represents a method that calls an external class5. Mixed boot order: StartService ()--Bindservice ( )--Unbindservice ()--StopService ()6, the service object can be strongly turned into a class name, can also be strong to the definition of the interface name, the following method can make a custom method of privatization, as long as the interface does not include your custom methodMF = (musicinterface) service;7, the broadcast can be registered with the code, but the service will have to register with the manifest file8. The onserviceconnected () method in the Serviceconnection () method is called when the Onbind has returned to this method, where the service object is the intermediary returned by Onbind; The onservicedisconnected () method is called when the connection is aborted because of an exception, and normal abort does not call9. Aidl--android Interface Definition language (Android Interface definition language)role: Cross-process communicationscenario: A man-in-the-middle object in a remote service, where other applications are not available, cannot be cast when a middleman object is acquired through the bind service, and with Aidl, it is possible to get the interfaces implemented by the intermediate human in other applications .Step:<1> Change the suffix name of the interface file to. aidl<2> All things in the Aidl file are public and do not need or define access modifiers themselves<3> Intermediary object inheritance stub (abstract class), stub object has inherited binder and implemented Publicbusiness interface In another project, you have to copy the above Aidl, the same as the package name--Get the Middleman object to use Stub.asinterface strong
10. How Android Studio uses Aidl <1> Select the package name you want to use, right-click, create a new Aidl file
<2> Write the method you want to implement
Debug
Reference Link:http://www.zhihu.com/question/21581761 11. Remote Payment--a remote payment interface + Payment interface (not under the same item)The 、—— a ndroid:gravity property is the qualification for the content in the view. For example, a button above the text. You can set the text to the left, right, and so on, relative to the view.

——  android:layout_gravity is used to set the location of the view relative to the parent view. For example a button in the LinearLayout, you want to put the button in the LinearLayout left, on the right and so on can be set by this property

13, if a style (such as the size of the display text, color, position, etc.) to use multiple times, you can in the values of the styles.xml A style is defined in the following example:
<style name= "Title" > <item name= "android:layout_width" >match_parent</item> <item name= " Android:layout_height ">wrap_content</item> <item name=" android:textsize ">30sp</item> &L T;item name= "android:gravity" >center</item> <item name= "Android:layout_margintop" >20dp</item > <item name= "Android:textcolor" > #ef1414 </item> </style>
If you want to change one of these properties, you can use inheritance, there are two ways, generally in the second type:
<style name= "Titles" parent= "Title" > <item name= "android:textsize" >10sp</item></style>  ; <style name= "Title.mytitles" >
<item name= "Android:textcolor" > #1410f4 </item> </style>
The theme "using" in the manifest file definition and style "use in Layout files" definition is the same, but the scenario is different14, internationalization and internationalization can support a variety of language implementation steps: <1> define display, in values--strings.xml <2> Create a package name to internationalize , naming conventions should also be internationalized, such as Values-en, to be strict with <3> content, you can directly copy the previous strings.xml, and then modify the picture can also be internationalized, ibid.

Broadcast and Service Summary 2

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.