Android face Test

Source: Internet
Author: User
Tags message queue

1. What are the four components of Android, and what are their roles?

Activityactivity is the window of the Android program interacting with the user, is the most basic of the Android building block, it needs to maintain the state of the various facets, do a lot of persistent things, properly manage the life cycle and some jump logic.
Service backend services to activity, encapsulation has a complete functional logic implementation, accept the upper instruction, complete the related food, define the need to accept the intent provide synchronous and asynchronous interface.
Content provider is an access scheme for third-party application data provided by Android, which can derive content provider classes, provide data externally, choose to sort like a database, mask the storage details of internal data, and provide a unified excuse model. Greatly simplifies upper-layer applications and provides a more convenient way to integrate data
Broadcast receiver accepts one or more intent as triggering events, accepts related messages, does some simple processing, transforms into a notification, and unifies the Android event broadcast model.

2, please introduce the five kinds of layouts commonly used in Android

Framelayout (Frame layout)
Everything in turn in the upper left corner, will overlap, this layout is relatively simple, can only put a little more simple things.
LinearLayout (Linear layout)
Linear layout, each linearlayout inside can be divided into vertical layout (android:orientation= "vertical") and horizontal layout (android:orientation= "Horizontal"). When vertical layout, there is only one element for each row, and multiple elements are descending vertically; when horizontal layout, there is only a row, and each element is arranged to the right.
Relativelayout (relative layout)
The relative layout can be understood as the layout of an element as a reference object. The main attributes are: relative to an element Android:layout_below, Android:layout_toleftof relative to the parent element android:layout_alignparentleft
Android:layout_alignparentrigh;
Tablelayout (Table layout)
Table layout, each of the tablelayout has a table row Tablerow,tablerow inside can define each element concretely.
Absolutelayout (Absolute layout)
Absolute layout with x, y coordinates to specify the position of the element, this layout is also relatively simple, but in the screen rotation, often problems, and multiple elements of the time, the calculation is more troublesome.

3. Life cycle of activity?

Oncreate: Called when the Activity object is created for the first time
OnStart: Call this function when activity becomes visible
Onresume: Called when activity starts and is ready to interact with the user
Onpause: A method that is called before the system starts another activity
Onstop: This method is called when the current activity becomes invisible.
OnDestroy: The method will be called before the current activity is destroyed
Onrestart: This method will be called before an activity is started again

Main:oncreate ()->onstart ()->onresume ()
Click the button to another activity
Main:onpause ()
Other:oncreate ()->onstart ()->onresume ()
Main:onstop ()
Return
Other:onpause ()
Main:onrestart ()->onstart ()->onresume ()
Other:onstop ()->ondestroy ()

4. What are the types of animations in Android, and what are their characteristics and differences?

Two kinds, one is tween animation, and another is frame animation. Tween animations, which enable the view component to move, zoom in, zoom out, and create transparency, another frame animation, a traditional animation method, is implemented by sequential playback of a well-arranged picture, similar to a movie.

5. What kinds of XML-parsing classes are in Android? What kind of official recommendation? and their principles and differences.

There are three main ways of parsing XML, SAX, DOM, pull.
General development on the PC we use the DOM relatively easy, but some performance-sensitive database or mobile phone is mainly sax, sax read is one-way, the advantages: not account for memory space, parsing properties convenient, but the disadvantage is that nested multiple branches for processing is not very convenient. And Dom Way will load the entire XML file into memory, where the Android Development network to remind you that the method in the search aspect can and XPath good combination if the amount of data is not highly recommended, and pull is often used in J2ME for node processing is better, similar to sax mode, Also very memory-saving, in J2ME we often use the Kxml library to parse.

6, say the principle of MVC mode, its application in Android, Android's official recommendation application development using MVC mode. What is MVC?

MVC is an acronym for Model,view,controller, and MVC consists of three parts:
Model object: Is the main part of the application, and all business logic should be written on that layer.
View object: Is the part of the application that is responsible for generating the user interface. It is also the only layer that the user can see in the entire MVC architecture, receiving input from the user and displaying processing results.
Controller (Control) object: is based on user input, control the user interface data display and update model object state of the part, the controller more important a navigation function, in response to the user to start the relevant events, to the M layer processing.
Android encourages weak coupling and component reuse, and MVC in Android is embodied in the following:
1) View layer: The general use of XML file interface description, when used can be very convenient to introduce, of course, if you know more about Android, you can think of Android can also use javascript+ HTML and so on as the view layer, of course, there is a need for the communication between Java and JavaScript, fortunately, Android provides a very convenient communication between them implementation.
2) control layer (Controller): The task of Android control layer usually falls on the shoulders of many acitvity, this phrase also implies do not write code in acitivity, to through activity delivery model business Logic layer processing, Another reason for this is that the response time of Acitivity in Android is 5s, and if time-consuming operations are put here, the program is easily recycled.
3) Model: the operation of the database, the operation of the network, etc. should be processed in the model, of course, business calculations and other operations must be placed in the layer.

7. Please explain the relationship between message, Handler, message Queue, Looper in single-threaded model

A: Simply put, Handler gets the Looper object in the current thread, Looper is used to remove the message from the MessageQueue that holds the message, and then handler to distribute and process the message.
Message queue: Used to hold a message published through handler, usually attached to a thread that created it, can get the message queue of the current thread through Looper.myqueue ()
Handler: You can publish or process a message or manipulate a runnable to publish a message through Handler, and the message will only be sent to the message queue associated with it, and only the messages in that message queue are processed.
Looper: Is the communication bridge between handler and message queue, the program component first passes the message to the Looper,looper by handler to put the message into the queue. Looper also broadcasts messages from the message queue to all
Handler:handler after receiving the message, call handlemessage for processing
Message: The types of messages that are processed by a single message in the Handlemessage method in the handler class
In a single-threaded model, for thread communication problems, Android has designed a message queue, which can be exchanged between threads through this message queue and in conjunction with handler and Looper components. They are described separately below:
1. Message
Message, which is understood as information exchanged between threads, and the processing of a data background thread needs to update the UI, sending a message contains some data to the UI thread.
2. Handler
Handler processor, is the main processor of the message, responsible for the delivery of the message, the execution of the message content processing. A background thread is a SendMessage (Message) by passing in a handler object reference. With handler, you need to implement the Handlemessage (message) method of the class, which is the action content that handles these Message, such as the update UI. It is often necessary to subclass handler to implement the Handlemessage method.
3. Message Queue
Message queue, used to store messages posted through handler, followed by FIFO execution.
Each message queue will have a corresponding handler. Handler sends messages to message queue in two ways: SendMessage or post. Both messages will be inserted at the end of the message queue and executed in FIFO. However, the messages sent by these two methods are slightly different: sending a Message object via SendMessage is handled by the handler Handlemessage () function, and a Runnable object is sent via the Post method. It will execute itself.
4. Looper
Looper is the steward of the message queue for each line thread. Android does not have a global message queue, and Android automatically creates a message queue for the main thread (the UI thread), but the message queue is not established on the thread line. So calling Looper.getmainlooper () gets the looper of the main thread is not NULL, but calling Looper.mylooper () gets the looper of the current thread to be null. The use of Looper,api doc for child threads provides the correct way to use: the approximate flow of this message mechanism:
1. After the Looper.loop () method runs, the non-null message inside the message queue is retrieved sequentially in the order in which it was received.
2. At the beginning of the message queue, the message is null. When Handler.sendmessage (message) to the message Queue, the function inside sets the target property of the message object to be the current handler object. The message is then processed by the DispatchMessage function of the hander called by the target of the message, which is then removed by Looper. In the DispatchMessage method, how to handle a message is specified by the user, three judgements, and priority from high to Low:
1) message inside the callback, a realization of the Runnable interface object, wherein the run function to do the work;
2) handler inside the Mcallback point to a realization of the callback interface object, by its handlemessage processing;
3) Processing the message handler object corresponding to the class inheritance and implement the Handlemessage function, through the implementation of the Handlemessage function to process the message.
Thus, the Handlemessage method we achieve is the lowest priority!
3. When handler finishes processing the message (update UI), Looper sets the message to NULL for recycling!
There are many articles on the web about how the main thread and other sub-threads interact, transmit information, and ultimately who will perform the processing of information, such as personal understanding is the simplest way-to determine the handler object inside the Looper object belongs to which thread, then by the thread to execute!
1. When the argument of the handler object's constructor is empty, it is the looper of the current thread;
2. Looper.getmainlooper () Gets the Looper object of the main thread, and Looper.mylooper () gets the Looper object of the current threads.

Android face Test

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.