Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Android Program Management

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to understand Android program management, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, people who have this need can learn, I hope you can gain something.

Making a complete Android program without using Activity is really a difficult thing. Because an Activity is the window through which Android programs interact with users.

From this perspective, Android activities look like website pages to me. First of all, a website, if there is no page, then..., He was truly a weirdo. And a page often has a separate theme and function point.

For example, login page, registration page, management page, etc. In each page, will put some links, has realized the function point of the series, some links point, brush, went to another page of the same site; some links point, chirp, may jump to other website pages;

There are also links, um... This time it didn't run, but the look of the current page may have changed. These patterns, and Activity gives people a feeling very similar, but the implementation strategy is different, after all, the core idea of Android architecture itself comes from the Mash-Up concept of the Web.

As a page client-side, it is also possible. Android program, in the four major components, is undoubtedly the most complex, these days, one thing and the interface is hooked up, can not be simplified, think about it, how much time to do an application independently on the interface, you can figure it out.

Visually, an Activity occupies the current window, responds to all window events, and has interface elements such as controls and menus. From an internal logic perspective, activities need to maintain the state of each interface. There's a lot of persistence to do, there's lifecycle management to do, and there's some jump logic. For developers, you need to derive a subclass of Activity and then work on the above. More details about activities.

Service, from the most straightforward point of view, is stripped of the interface of the Activity, they are relatively close in many Android concepts, are packaged with a complete functional logic implementation, but Service does not show its face, just silently do solid backing.

But in fact, from another point of view, Android services, and we usually say Windows services, Web background services have some similarities, they are usually running in the background for a long time, accept high-level instructions, complete related transactions module.

In run mode, Activity is jumping, jumping from one to another, er... It's kind of like modal dialogs (or web pages, okay...), Given an input (or no...), Then let it run regardless, returning output when it leaves (with or without...). Service is not, it is waiting, waiting for the upper layer to connect to it, and then generate a long-lasting and lingering communication, which is like a page using Ajax, looking at nothing changes, sneaky and Service I don't know how many times.

However, it is still different from the general Service. Android Service is the same as all four components. Its process model can be configured. Both the caller and the publisher can choose whether to run this component under the same process.

or under different processes. This sentence, you can take a nail clipper engraved into the mind, it highlights the operating characteristics of Android. If a Service is expected to run in different processes on the caller, it needs to deploy a set of inter-process communication policies for it using the RPC mechanism provided by Android.

RPC implementation for Android, as shown above (well, also taken from SDK...), Not surprisingly, an implementation based on the proxy pattern generates a proxy class on both the caller side and the server side, doing some serialization and deserialization so that both the caller side and the server side can use the RPC interface as if it were calling a native interface.

The class used to serialize data in Android is Parcel, see: /reference/android/os/Parcel. html, which encapsulates the details of serialization and provides enough object-oriented access interfaces. Android claims to be very efficient. AIDL (Android Interface Definition Language)

An interface definition language, RPC interfaces for services, can be described in AIDL, so ADT can help you automatically generate a complete set of classes needed for proxy patterns, which are very hard to think of and write. For more information, please check out guide/developing/tools/aidl.html. If you are interested, you can find some other PRC implementation materials lou.

For the implementation of Service, also strongly refer to the RemoteService implementation in the Android program Sample. It shows exactly what it takes to implement a Service: define the intents that need to be accepted, and provide synchronous or asynchronous interfaces.

After binding it at the upper layer, it passes through these interfaces (many times RPC's...) Communication. Data used in RPC interface, callback interface object, if not standard system implementation (system serializable), you need to customize aidl, everything, in this Sample has expression, strongly recommended.

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report