Android Engineer Interview Prep Knowledge Point

Source: Internet
Author: User
Tags message queue

Listen to +7 elder brother said, the following all understand, interview must pass, so I tried to add to all the topics, you can be friends, if there is a spit groove or supplementary despite the message to me, here to thank you.

1. How to communicate with multi-threaded Android

A: Android provides handler and Looper to meet the communication between threads.

Handler is the processor of the message that can publish or process or manipulate a runnable, handler accept the message and call handlemessage for processing.

Looper is a bridge between the handler and the message queue, and the program component passes the message to the Looper,looper by handler and puts the message into the queue.

2. The multi-process communication principle of Android

A: The way Android enables cross-process communication is by using the Aidl method

Aidl (Android Interface Description Language) is an interface port description language;  The compiler can generate a piece of code through the Aidl file, which achieves the purpose of two process internal communication processes through a pre-defined interface. If you need to access an object in another service in one activity, you need to first turn the object into a aidl-recognizable parameter (possibly multiple parameters), then use Aidl to pass these parameters, and at the receiving end of the message, use these parameters to assemble the objects that you need.

Principle: The communication information between processes will be converted to the AIDL protocol message first, then sent to the other side, the other party receives the AIDL protocol message and then converts to the corresponding object. Since the communication between the processes requires two-way conversion, Android uses the proxy class behind the two-way transformation of information, the proxy class is generated by the Android compiler, the developer is transparent.

3. How to use Android five components

Answer: Activity, Intent, Service, Content provider,broadcast Receiver

Activity: literally means "active", which is simply a screen that sets the interface to be displayed by calling Setcontentview ().

Intent: means "intention", can realize the interaction between activity and activity, pass data.

Service: Represents services, as the activity defaults to the main thread, but it does not have a visual interface and is run in the background. Start the service by calling the StartService or Bindservice method to start.

Content Provider: Introduced to solve the problem of data communication and sharing among applications.

Broadcast receiver: Broadcast receivers, Android broadcasts either from the system or from a normal program.

You can register a broadcast receiver in Androidmenifest.xml or in code.

4. What is the default thread for service startup?

A: The default startup is the main thread

5. Which design patterns have been used for development

Answer: Singleton mode, Factory mode, observer mode

6. What are the advantages and disadvantages of the thread pool

A: The advantage is to reduce the consumption of the creation thread, each time the creation thread is taken from the thread pool.

The disadvantage is that memory is always occupied.

7. The characteristics of various layout methods, how to use

For:

Linear layout-linearlayout

orientation-the arrangement of elements within a container.

Vertical: Child elements are arranged vertically

Horizontal: Child elements are arranged horizontally

This is the most used layout, by setting the orientation to determine how the child elements are arranged.

Absolute layout-abolutelayout

LAYOUT_X:X coordinates. The top-left corner is the vertex.

Layout_y:y coordinates. To make the upper corner a vertex.

The layout was abandoned, not flexible enough.

Relative Layout-relativelayout

layout_centerinparent– the center position of the current element in the horizontal and vertical directions within its container (similar properties are: Layout_centerhorizontal,layout_alignparentleft, etc.)

layout_marginleft– sets the distance of the current element relative to the left edge of its container

layout_below– Place the current element below the specified element

layout_alignright– the current element right-aligned with the specified element

This layout is often used, generally want a complex layout, it is indispensable, because it can be well positioned.

Table Layout-tablelayout

The table layout primarily manages the child controls in rows and columns, where each row is a TableRow object, and each TableRow object can add child controls, and each of the controls is equivalent to adding a column.

Frame Layout-framelayout

Also called cascading layouts. With the top left corner as the starting point, the elements within the framelayout layer are covered by one layer, and in the frame layout, the first image that is added is overwritten by the image that is added later.

8.android of database use is familiar with

A: SQLite is a lightweight database embedded in Android, saying that I do not use much, not very familiar.

What is the difference between 9.android XML parsing

A: The XML file can be parsed on the Android platform using sax (simple API for XML), the document Object Model (DOM), and the pull parser included with Android.

Dom parsing : When working with large files, its performance drops very badly. This problem is caused by the tree structure of the DOM, which takes up more memory, and the DOM must load the entire document into memory before parsing the file, which is appropriate for random access to the XML

Parsing process:

1. Get Factory

Documentbuilderfactory builderfactory =documentbuilderfactory.newinstance ();

2. Get Builder

Builder =builderfactory.newdocumentbuilder ();

3. Parse to Document Object

Document document = Builder.parse (xmlfile);

4. Get the root element

Element root = Document.getdocumentelement ();

5. Get the child nodes under the root element

NodeList childNodes =root.getchildnodes ();

Sax parsing : Unlike Dom,sax, an event-driven XML parsing method. It reads the XML file sequentially and does not need to load the entire file at once. When it encounters a file beginning with a document ending, or the beginning of a label with the end of the label, it triggers an event that the user processes the XML file by writing the processing code in its callback event, which is appropriate for sequential access to the XML.

1. Get Factory

SAXParserFactory factory =saxparserfactory.newinstance ();

2. Get parser

SAXParser parser =factory.newsaxparser ();

3. Start parsing

Parser.parser (XMLFile, Newmysaxlistener ());

Pull parsing : In addition to parsing XML files using sax and DOM, you can also parse an XML file using the built-in pull parser of Android. The pull parser operates in a similar way to the SAX parser. It provides similar events such as starting and ending element events, using Parser.next () to move to the next element and triggering the corresponding event. Events are sent as numeric codes, so you can use a switch to handle the events of interest. When the element begins parsing, the Parser.nexttext () method is called to get the value of the next text type element.

1. Get parser

Xmlpullparserparser = Xml.newpullparser ();

2. Setting the input

Parser.setinput (instream, "UTF-8");

3. Get the event type

int eventtype = Parser.geteventtype ();

4. Start parsing

What is the difference between a 10.android base class library, such as List, Set, HashSet, and how to exclude duplicate data

For:

Android.app: Provides a high-level program model and provides a basic operating environment

Android.content: Contains a variety of classes for accessing and publishing data on a device

Android.database: Browsing and manipulating databases through content providers

Android.graphics: The underlying graphics library, which contains the canvas, color filters, dots, rectangles, can draw them directly onto the screen.

Android.location: Classes for targeting and related services

Android.media: Provides some classes to manage multiple audio and video media interfaces

Android.net: A class that provides help for network access, more than the usual java.net.* interface

Android.os: Provides system services, message transmission, IPC mechanisms

ANDROID.OPENGL: Tools to provide OpenGL

Android.provider: Provides class access to Android content providers

Android.telephony: Providing API interaction with call-related calls

Android.view: Provides a basic interface framework for the user interface

Android.util: Methods involving tools, such as the operation of a time-date

Android.webkit: Default Browser operator interface

Android.widget: Contains various UI elements (mostly visible) used in the application's screen

The list saves objects in the order in which they are entered, without sorting or editing operations. Set accepts only once for each object and uses its own internal ordering method (typically, you are only concerned about whether an element belongs to set, not the order of it – otherwise you should use list).

Specific View http://blog.csdn.net/wwj_748/article/details/7883988

11. Have done something, introduce.

A: I have done a news client, and a music player, the internship is doing is a voice mail client, is developing a Sina Weibo client.

1. News client is one of my works in the University of Software Development Contest, it is a mobile phone application, used to display news information, users can view and comment on the news.

2. Jane, Mei Music player is my own research and development of a music player, in the spirit of want to do a simple, beautiful music player for their own use.

3. Language mailbox is my own in the internship company to participate in the development of a product, is a product of our company.

4. Sina Weibo client is one of my advanced projects, want to be familiar with the use of Sina Weibo development platform API, for their own development of other open platform to do a cushion, is still in development.

12. Touch screen Processing process

A: The event delivery order is viewgroup::onintercepttouchevent () –>viewgroup or view ontouchevent () –> activity::ontouchevent ()

1. When the Viewgroup::onintercepttouchevent () return value is False, the event (pressed, moved, lifted, and so on) is passed to the target view. If the viewgroup is triggered, call Viewgroup::ontouchevent () and call View::ontouchevent () If the view is triggered;

2. When the Viewgroup::onintercepttouchevent () return value is true, the event is passed directly to viewgroup::ontouchevent () processing. In other words, the moving, lifting action after the event does not go through onintercepttouchevent (), but is transmitted directly to Ontouchevent ().

3. When the Viewgroup::ontouchevent ()/view::ontouchevent () return value is true, the pressed action event is processed, which means that subsequent actions such as moving, lifting, and so on, will be propagated to this method. If it is view processing, viewgroup::ontouchevent () will not get the event, and if it is viewgroup processing, activity::ontouchevent () will not be active.

4. When the Viewgroup::ontouchevent ()/view::ontouchevent return value is False, indicating that the event is not handled, the system will pass the event to its parent processing.

5. Activity::ontouchevent () This is the last place to be processed, and if not, the system discards the event.

Summary: Onintercepttouchevent () is used to distribute events, ontouchevent () is used to deal with events, who do not handle it to the upper level of processing, layer by layer pass.

13.activity process

Answer: Create oncreate-start onstart– start onresume– pause onpause– end onstop– Destroy OnDestroy

During the normal start of an activity, they were called in the order of OnCreate->onstart--onresume, when the activity was killed, OnPause, OnStop OnDestroy, this is a complete life cycle.

Explain in detail what the system is doing and what we should do in these methods:

OnCreate: Create the interface here and do some initialization work on the data

OnStart: To this step becomes user visible non-interactive

Onresume: To become interactive with the user, (in the activity stack system through the way of the stack to manage these

Top of activity, run out of pop-up stack, then go back to previous activity)

OnPause: To this step is visible but not interactive, the system will stop the animation and other CPU-consuming things

As already known from the above description, you should save some of your data here, because at this time

Your program's priority is reduced and may be withdrawn by the system. The data that is stored here should be in

Onresume read it out, note: This method is done in short time, because the next

Activity will not be activated until this method is completed.

OnStop: becomes invisible and is covered by the next activity

OnDestroy: This is the last method that was called before the activity was killed, possibly the outer class called the finish side

method or system to save space and temporarily kill it, you can use isfinishing () to judge

Break it, if you have a progressdialog in the thread to turn, please in OnDestroy

Cancel him off, or else when the thread ends, the Cancel method that calls dialog will throw

The exception.

Onpause,onstop, OnDestroy, in three states, the activity could be killed by the system.

In order to ensure the correctness of the program, you have to write the persistent layer code in OnPause () to save the user's edits to the storage media (usually the database). There are a lot of problems in the actual work because of the change of life cycle, such as when your application has a new thread running, it breaks down, you still have to maintain that thread, whether it's pausing or killing or data rollback, right? Because the activity could be killed, Therefore, the variables used in the thread and some interface elements must be noticed, generally using the Android message mechanism [Handler, message] to deal with multithreading and interface interaction problems.

14. How to prioritize your programs to avoid being killed when the system is running out of memory

A: In order to increase the thread priority (thread-priority) of threads in our activity, we can use the uses-permission tag in Androidmanifest.xml. You can do this:

<uses-permissionid= "Android.permission.RAISED_THREAD_PRIORITY"/>

Then set the thread priority in the activity code

Process.setthreadpriority (Process.thread_priority_background);//Set the thread to be in the background, so that when multiple threads are concurrent, many insignificant threads will be allocated less CPU time. facilitates the processing of the main thread, the relevant thread priority definitions are listed in the following categories:

int Thread_priority_audio//thread priority used by standard music playback

int Thread_priority_background//Standard daemon

int Thread_priority_default//priority of default app

int Thread_priority_display//Standard display system priority, mainly to improve UI refresh

int Thread_priority_foreground//Standard foreground thread priority

int thread_priority_less_favorable//below favorable

int thread_priority_lowest//valid thread lowest priority

int thread_priority_more_favorable//above favorable

int Thread_priority_urgent_audio//Standard more important audio playback priority

The int thread_priority_urgent_display//standard is more important than the display priority and is also applicable for input events.

Android Engineer Interview Prep Knowledge Point

Related Article

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.