It is really difficult to build a complete Android program and don't want to use Activity, unless you want to be crazy. Because Activity is a window for interaction between Android apps and users, you are welcome to learn.
In my opinion, from this perspective, the webpage of the Android Activity website is displayed. First of all, if a website does not have a page, it is a wonderful thing. A page usually has an independent topic and function.
For example, the logon page, registration page, and management page. In each page, some links are put, and feature points are connected in series. Some links are clicked and brushed to another page on the same site. Some links are clicked, closed, may jump to the pages of other websites;
Another link is clicked. Well... this time it didn't run, but the current page may have changed. These models are similar to Activity, but their implementation strategies are different. After all, the core idea of the Android architecture comes from the Web-based Mash-Up concept.
It is regarded as a client of the page, and it cannot be tasted. The Android program is undoubtedly the most complex among the four main components. During the past few years, the hooks of one thing and the interface cannot be simplified. Think about it, you can figure out how much time it takes to create an independent application on the interface.
In terms of visual effects, an Activity occupies the current window, responds to all window events, and has interface elements such as controls and menus. From the internal logic, the Activity needs to maintain the status of each interface. We need to do a lot of persistent things, and also properly manage the lifecycle and switch logics. For developers, they need to derive a subclass of the Activity, and then work hard to do the above. More details about the Activity.
Service, in the most straightforward view, is to strip the Activity of the interface. They are very similar in many Android concepts and are encapsulated with a complete functional logic implementation, however, the Service is not exposed, but it is a solid backing silently.
But in fact, from another perspective, the services in Android are similar to the Windows Services and Web Background services that we usually call. These services are usually used for long running of the background and accept upper-layer commands, the module that completes related transactions.
In running mode, Activity jumps from one to the other ..., this is a bit like a modal dialog box or a web page ...), give an input or no ...), then, regardless of whether you want it to run, the same output or no... will be returned when it leaves ...). The Service is not, it is waiting, waiting for the upper layer to connect to it, and then generate a persistent and lingering communication, which is like an Ajax page, watching nothing changed, sneaky and Service, I don't know how many times it went.
However, unlike general services, the process model of Android services is configurable like all four components, both the caller and the producer can choose to run this component in the same process.
Or different processes. This sentence can be engraved into your mind, which highlights the running characteristics of Android. If a Service is expected to run in different processes of the caller, you need to use the RPC mechanism provided by Android to deploy a set of inter-process communication policies for it.
The RPC implementation of Android, as shown in. It also comes from the SDK ...), nothing unusual. Based on an implementation of the proxy mode, a proxy class is generated on both the caller and the server side for serialization and deserialization, this allows both the caller and server to use the RPC interface just like calling a local interface.
The class used for data serialization in Android is Parcel. For details, see/reference/android/OS/Parcel.html. This class encapsulates the serialization details and provides an access interface that is sufficiently object-oriented, android is said to be very efficient. There is also AIDL (Android Interface Definition Language ).
The language defined by an interface and the RPC interface of the service can be described using AIDL. In this way, ADT can help you automatically generate a complete set of classes required for the proxy mode, it's the kind of hard work that I think. For more information, see guide/developing/tools/aidl.html. If you are interested, you can find other PRC implementation materials lou.
For more information about the Service implementation, see the RemoteService implementation in the Android program Sample. It fully demonstrates what a Service needs to do: Define the Intent to be accepted and provide synchronous or asynchronous interfaces.
After it is bound to the upper layer, many of these interfaces are called RPC...) for communication. The data and callback interface objects used in the RPC interface, if not serialized by the standard system implementation system), you need to customize aidl, everything, in this Sample, there are expressions and strong recommendations.