Android Practice Project report (II)

Source: Internet
Author: User

2 Project related technology introduction and analysis

This part of the project development related technology to introduce and analyze, Android operating system content includes: System architecture and application program. Development process Technology includes: Android file storage method, call Youdao API to translate.

2.1 Android operating system

Android is a Linux-based open-source operating system that is used primarily for portable devices. Android is a complete, open, and free mobile platform with the following outstanding features:

1) Openness: In terms of dominance, the Android platform is first and foremost its openness, and the open platform allows any mobile terminal vendor to join the Android Alliance. Significant openness makes it possible to have more developers, and as users and applications become richer, a new platform will soon mature.

2) Application no bounds: Android apps can access core mobile devices through standard APIs. Through the Internet, applications can be used by other applications for their functionality.

3) applications can be embedded easily into the network: applications can easily embed HTML, JavaScript, and stylesheets, as well as display network content through WebView.

4) Seamless combination of Google Apps: Android platform phone can be a good combination of Google services. such as Google Maps, mail, search and so on.

2.1.1Android System Framework

The Android operating system architecture, like other operating systems, employs a layered architecture. From the architecture diagram, the Android system architecture is a four-tier structure, from the upper level to the lower layer, the application layer, the application framework layer, the System runtime layer, and the Linux kernel tier. 2-1 is shown below:

Figure 2-1 Android System frame diagram

(1) Application layer

The tier provides core application packages such as e-mail, text messages, calendars, maps, browser and contact management. At the same time, developers can use the Java language to design and write their own applications, which are equal and friendly with those core applications.

(2) Application framework Layer

This layer is the basis for Android app development, and most of the time developers are dealing with her. The application framework layer includes the Activity Manager, window Manager, content provider, view system, Package Manager, Phone manager, resource manager, Location manager, Notification Manager, and XMPP Services 10 sections. On the Android platform, developers have full access to the API framework used by the core application. Also, any application can publish its own module of functionality, while other applications can use these published function modules. Based on this reuse mechanism, users can easily replace the various application components of the platform itself.

(3) System library and Android runtime

The system library consists of nine subsystems, layer management, Media Library, SQLite, Openglestate, FreeType, WebKit, SGL, SSL, and libc. The Android runtime includes both the core library and the Dalvik virtual machine, which are compatible with the function functions that most Java languages need to invoke, and the core libraries of Android, such as Android.os, Android.net, Android.media, and so on. The latter is a register-based Java Virtual machine, Dalvik virtual machine is to complete the life cycle management, stack management, thread management, security and exception management, garbage collection and other important functions.

(4) Linux kernel

Android Core system services rely on Linux2.6 cores such as security, memory management, process management, network protocol stacks, and drive models. The Linux kernel is also an abstraction layer for hardware and software stacks. Drivers: Display drivers, camera drivers, keyboard drivers, wifi drivers, audio drivers, flash memory drivers, Binder (IPC) drivers, power management, and more.

2.1.2 Android Application

The Android application layer consists of four main components: activity, which is used for display functions, service, equivalent activity in the background, broadcast (BROADCASTRECEIVER) for receiving broadcast Content provider (Intent), which is used to store and retrieve data.

(1) Activity

An activity is usually presented as a visual user interface, a window into which the Android program interacts with the user, and is the most basic and complex component of the Android component. From a visual perspective, an activity occupies the current window, responds to all window events, has controls, menus, and other interface elements. From the internal logic, the activity needs to do a lot of persistence in order to maintain the various interface states, but also need to manage the life cycle, and some of the jump logic. For developers, it is necessary to derive a subclass of activity, which can be encoded to implement various functional methods.

(2) Service

Service is a component running in the background, and in a sense, the service is like an activity without an interface. They are close to many of the Android concepts, encapsulating a complete functional logic implementation, accepting upper-level instructions, completing related events, and defining the intent to be accepted to provide synchronous and asynchronous interfaces. Android is actually a service similar to what is available in Windows, it performs long-running operations, or the process performs work. The service does not provide a user interface, such as downloading things in the background, playing music, and doing other things while you play the music, without blocking the interaction with other activities. Another component, such as activity, can start a service and run or bind to it.

(3) Broadcast Receiver

Broadcast receivers, without performing any tasks, broadcast is a widely used mechanism for transferring information between applications. The broadcastreceiver is a type of component that filters and responds to the broadcast being sent. Broadcast Receiver does not contain any user interface. However, they can initiate an activity in response to the received information, or notify the user via Notificationmanager. There are several ways to make users aware of new notifications: flashing background lights, vibrating devices, making sounds, and more. Typically, the program places a persistent icon on the status bar where the user can open the icon and read the notification message. Another important concept in Android is intent, if intent is an abstract description of actions and behaviors, responsible for message passing between components. Then the broadcast receiver component provides a mechanism to broadcast intent as a message and to react to it by all programs that are interested in it.

(4) Content Provider

As the only way to share data between applications, Content Provider's primary function is to store and retrieve data and provide interfaces to other applications to access the data. One of the unique features of Android is that in Android, each application uses its own user ID and runs in its own process. The benefit is that the system and applications can be effectively protected from other unhealthy applications, each with a separate process address space and virtual space. Android data (including files, database, etc...) ) belongs to the application itself, other applications are inaccessible and cannot be manipulated directly. So if you want to implement data sharing between different applications, you have to use content provider. To enable other programs to manipulate data, in Android, you can provide an interface for data manipulation by making contentprovider. In fact, for the application, the underlying data can also be encapsulated into ContentProvider, which can effectively mask the details of the underlying operations, and to keep the program good extensibility and openness.

2.2 Calling Youdao Translation API

Youdao translation API, for the vast number of developers to provide an open interface. Your application or website can use Youdao translation API to build a rich variety of functions or applications, to bring users instant, accurate, convenient search words or translation experience, thereby reducing the language understanding and application threshold. Rely on Youdao translation network data Mining and statistical machine translation technology strength to do the foundation, coupled with your wisdom, will create a better experience and innovative features.

JSON data Format examples

Http://fanyi.youdao.com/openapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=json &version=1.1&q=good

{

"ErrorCode": 0

"Query": "Good",

"Translation": ["good"],//Youdao translation

"Basic": {//Youdao dictionary-Basic Dictionary

"Phonetic": "G?d"

"Uk-phonetic": "G?d"//English pronunciation

"Us-phonetic": "ɡ?d"//American pronunciation

"explains": [

"Benefits",

"Nice and good"

Good

]

},

"Web": [//Youdao Dictionary-Network interpretation

{

"Key": "Good",

"Value": ["good", "good", "good"]

},

{...}

]

}

In the project search Word module translation module by accessing the network interface, parsing the return results display data, the key part of the code is: public static Word DOTRANSLATECC (String query) {

Word word = null;

The following URL is the application of Youdao API key

String urlstr = "http://fanyi.youdao.com/openapi.do?keyfrom=justTec&key=1249502330&type=data&doctype= json&version=1.1&q= "+ query;

HttpClient HttpClient = new defaulthttpclient ();

Try {

String jsondata = "";

Sends an Http request to the specified URL

HttpResponse response = Httpclient.execute (new HttpGet (URLSTR));

Get the response returned by the server

httpentity entity = response.getentity ();

BufferedReader BufferedReader = new bufferedreader (new InputStreamReader (Entity.getcontent ()));

String line = "";

while (line = Bufferedreader.readline ()) = null) {

Jsondata = Jsondata + line;

}

Word = new word ();

Detailed please Baidu Youdao API

Jsonobject jsonobject = new jsonobject (Jsondata);

Word.setquery (query);

Word.settranslation (Jsonobject.getjsonarray ("translation"). GetString (0));

Jsonobject basic = Jsonobject.getjsonobject ("basic");

Phonetic

Word.setuk (basic.getstring ("uk-phonetic"). Trim ());

Word.setus (basic.getstring ("us-phonetic"). Trim ());

Returns a JSON array

String otherstring = "";

Jsonarray Otherarray = Basic.getjsonarray ("explains");

for (int i = 0; i < otherarray.length (); i++) {

Otherstring + = ";" + otherarray.getstring (i);

}

Word.setexplains (otherstring.substring (1));

} catch (Exception e) {

}

return word;

}

}

Problems encountered

DPAD not enabled in AVD

Open the Android emulator, the right part of the key to the next key to the following phenomenon:

I can't use the buttons.

I looked at several forums, plus my own summary, the solution is as follows:

1. Open the Android AVD in eclipse

2. Select any of them and click Details on the right.

3. Follow the address of path to locate the file

4, open the folder, find the Config.ini file inside, modify

5. After saving, after restarting the AVD, the results are as follows:

Haha, done!!!

Android Practice Project report (II)

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.