Android face Test is not just an interview is a good learning

Source: Internet
Author: User

The following questions are found in the online summary, thank you for sharing. Hope, our common progress, find their favorite company,:


1.android DVM Process and Linux this process, both application-to-the-same concept:

Answer: DVM is a dalivk virtual machine.

Each Android application executes in its own process. Has a DALIVK virtual machine instance.

And each DVM is a process in Linux. So I can feel the same concept.

What kinds of animations are there in 2.android? What are their characteristics and differences?

A: Two kinds, one is tween animation, one is frame animation. Tween animations enable the view components to move, zoom in or out, and create changes in transparency. Frame animation, the traditional method of animation, through the sequence of playback arranged by the picture to achieve. Like a movie.

The principle of 3.handler binary:

A: Android provides handler and Looper to meet the communication between threads. Handler first-out principle. Looper is used to manage the exchange of messages (message exchange) between objects within a particular thread.

1) Looper: A thread can produce a Looper object that manages the message queue of this line thread

2) Handler: You can construct a handler object to communicate with Looper in order to push new messages into the MessageQueue, or to receive messages sent from Looper (removed from MessageQueue).

3) MessageQueue: used to store messages placed by the thread.

4) Thread: The UI thread is usually the main thread, and the Android launcher creates a message queue for it.

4.android View Refresh:

A: There are many ways to update the view in Android, so you need to distinguish between different applications when you use them. I feel that the most important thing is to distinguish between multithreading and double buffering usage.

1). Do not use multithreading and double buffering

This is the simplest scenario, and it's generally just that you want to redraw the UI when the view changes. You just need to explicitly invoke the Invalidate () method in the View object in the activity.

The system will invoke the view's OnDraw () method on its own initiative.

2). Use multithreading and do not use double buffering

This situation requires a new thread to be opened, and the newly opened thread is not a good way to access the View object. A forced interview will be reported: Android.view.viewroot$calledfromwrongthreadexception:only the originalthread that created a view hierarchy can touch its views.

At this point you need to create a subclass that inherits the Android.os.Handler. and override the Handlemessage (messagemsg) method. Android.os.Handler is capable of sending and processing messages, you need to send a message in the activity that updates the UI. Then your handler (the ability to use anonymous inner classes) to process messages (because anonymous inner classes are able to access the parent class variables.) You can directly invoke the invalidate () method in the View object. That is, a message is created and sent on a new thread, and then captured and processed in the main threads.



3). Use multithreading and double buffering

Surfaceview in Android is a subclass of view. She also achieved double buffering at the same time. You can define a subclass of her and implement the Surfaceholder.callback interface. Because the implementation of the Surfaceholder.callback interface, the new thread will not need to android.os.Handler help. The Lockcanvas () method in Surfaceholder can lock the canvas. It is easier to call Unlockcanvasandpost (canvas) to unlock (display) after plotting to play a new image.

5. Talk about the MVC pattern principle, its use in Android:

A: The official Android recommendation application is developed using the MVC pattern.

What is MVC?

MVC is an acronym for Model,view,controller, and MVC consists of three parts:

L Model object: is the body part of the application. All of the business logic should be written on that layer.

2 View object: Is the part of the application that is responsible for generating the user interface. is also the only layer that users can see throughout the MVC architecture. Receives the user's input, displays the processing result.

3 Controller object: is based on the user's input, control the user interface data display and update model object state of the part, the controller more important a navigation function, want to use the user to start the related events, to M oh got processing.

Android encourages weak coupling and reuse of components. The detailed embodiment of MVC in Android is as follows:

1) View layer: The general use of XML file interface descriptive narrative, when used can be very convenient to introduce, of course. How much more you know about Android. will be able to think of in Android can also use javascript+html and so on as the view layer, of course, there is a need for Java and JavaScript communication between, fortunately, Android provides a convenient communication between them implementation.

2) control layer (Controller): The task of Android's control layer usually falls on the shoulders of many acitvity, which implies not to write code in acitivity. Another reason to do this is to deliver the model business logic layer through activity: The response time of Acitivity in Android is 5s. Assuming time-consuming operations are placed here, the program is very easy to recycle.

3) Model: the operation of the database, the operation of the network, etc. should be dealt with in models. Of course, operations such as business calculations must also be placed on that layer.

6.Activity Life cycle:

Answer: onCreate: Create the interface here. Do some initialization work on the data

OnStart: To this step becomes user visible non-interactive

Onresume: It becomes interactive with the user, (the activity stack system manages the top of these activity by means of a stack.) After executing the pop-up stack, go back to the previous activity)

OnPause: To this step is visible but not interactive, the system will stop the animation and other CPU-consuming things from the description described above have been known. You should save some of your data here, because your program's priority is reduced and may be withdrawn by the system. The data that is stored here should be in

OnStop: becomes invisible. Covered by the next activity.

OnDestroy: This is the last method to be called before the activity is killed, perhaps the outer class calls the Finish method or the system to save space and temporarily kill it.

7. Make activity into a form:

A: The Activity property is set: Sometimes the app is floating on the phone's main screen.

This only needs to be set under the theme of activity theme, that is, in the manifest.xml definition of activity, add a sentence:

Android:theme= "@android: Style/theme.dialog"
The assumption is to make a translucent effect:

Android:theme= "@android: Style/theme.translucent"

Five types of layouts that are commonly used in 8.Android:

Answer: linearlayout linear layout. Absolutelayout absolute layout; tablelayout table layout; relativelayout relative layout; framelayout frame layout;

Five ways to store data in 9.Android:

Answer: Sharedpreferences. a file; SQLite. ContentProvider; network

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

A: Handler gets the Looper object in the current thread, Looper is used to remove the message from the message queue that contains the message, and the handler to distribute and process the message.

What is the full name of 11.AIDL?

How does it work? What types of data can be processed?

Answer: Aidl (androidinterface Definition Language) Android interface descriptive narrative language

12. There are many browsers installed on the system, can you specify a browser to access the specified page ? Please explain the original:

A: Take the reference by sending a URI directly, or through the Data property in the Intentfilter in manifest. The code is as follows:
Intent Intent = new Intent ();

Intent.setaction ("Android.intent.action.View");

Uri uribrowsers = Uri.parse ("http://www.sina.com.cn");

Intent.setdata (uribrowsers);

Package name, activity to open
Intent.setclassname ("Com.android.browser", "com.android.browser.BrowserActivity");

StartActivity (Intent);

13. What is ANR and how to avoid it?

Answer: The definition of ANR:

On Android. Assuming your application has a time-sensitive response, the user is prompted with an "Application Not Responding" (Anr:application not responding) dialog box. Therefore, it is important to design the response performance in the program so that the system does not show the ANR to the user.

How to avoid:

Start by studying why it happens in Android applications and how best to build applications to avoid ANR.
Android applications are typically executed in a separate thread (for example, main), which means that what your application is doing assumes that it takes a long time in the main thread to raise the ANR dialog box. Because your application does not give you the opportunity to handle input events or intent broadcasts.

As a result, perform as little as possible on any visit to the mainline thread. In particular, activity should be created as little as possible in its critical life-cycle approach (OnCreate () and Onresume ()). Potentially time-consuming operations, such as network or database operations, or high-time calculations such as changing the bitmap size. The thread should be in the sub-line (or as an example of a database operation.) By way of an asynchronous request).

However, not that your main thread is stuck there waiting for the child thread to complete---is not called thread.wait () or Thread.Sleep (). The workaround is that the main thread should provide a handler for the child thread so that it can be submitted to the main thread when it is finished.

Design your application in such a way. Will ensure that your main thread remains responsive to the input and can avoid the ANR dialog box raised by the time-out of the 5-second input event.

Such practices should be emulated in other threads that display the UI because they are affected by the same timeout.

The special limitation of the Intentreceiver runtime means it should: do small, trivial work in the background, such as saving settings or a notification. Same as other methods that are called in the main thread. Applications should avoid time-consuming operations or calculations in Broadcastreceiver, but do not do these tasks in sub-threads (due to the short life cycle of broadcastreceiver), instead, assuming that the response intent broadcast requires a time-consuming action to run, The application should start a service. Incidentally, a word. You should also avoid starting an activity in intent receiver because it creates a new screen and grabs the focus from the program that the current user is running. Suppose your application needs to show the user what to do in response to intent broadcasts, you should use Notification Manager.

In general, in the application. 100 to 200ms is the time threshold at which the user can perceive the block. Here's a summary of some tips to avoid ANR and help make your application look responsive.

Assuming your application is working behind the scenes in response to user input, you can show the progress of your work (ProgressBar and progressdialog are very useful for such situations). In particular the game, in the sub-thread to do mobile computing. Assuming your program has a time-consuming initialization process, consider being able to display a splash screen or a high-speed display of the main picture and asynchronously populate the information. In both cases, you should show the progress you are making. To prevent users from feeling that the program is frozen.

14. What causes Force Close? How to avoid it? Can you catch the exception that caused it?

A: such as a null pointer can lead to forceclose, be able to see Logcat, and then find the appropriate program code to resolve the error.

15. The life cycle of the activity when switching between the screens and the screen:

For:

1) Create a new activity and print out the various life cycles

2) Perform activity and receive information such as the following:

OnCreate () à

OnStart () à

Onresume () à

3) when switching Cheng by ctrl+f12

Onsaveinstancestate () à

OnPause () à

OnStop () à

OnDestroy () à

OnCreate () à

OnStart () à

Onrestoreinstancestate () à

Onresume () à

4) then press CTRL+F12 to switch to vertical screen, found that two times the same log was printed

Onsaveinstancestate () à

OnPause () à

OnStop () à

Ondestroyà

OnCreate () à

OnStart () à

Onrestoreinstancestate () à

Onresume () à

Onsaveinstancestate () à

OnPause () à

OnStop () à

Ondestroyà

OnCreate () à

OnStart () à

Onrestoreinstancestate () à

Onresume () à

5) Change Androidmanifest.xml, add the activity to android:configchanges= "orientation", run step 3

Onsaveinstancestate () à

OnPause () à

OnStop () à

OnDestroy () à

OnCreate () à

OnStart () à

Onrestoreinstancestate () à

Onresume () à

6) Change the Androidmanifest.xml, add the activity to android:configchanges= "orientation", run step 4, found no longer print the same information, But more than one line is printed onconfigchanged

Onsaveinstancestate () à

OnPause () à

OnStop () à

OnDestroy () à

OnCreate () à

OnStart () à

Onrestoreinstancestate () à

Onresume () à

Onconfigurationchanged () à

7) Change the android:configchanges= "orientation" of step 5 to

Android:configchanges= "Orientation|keyboradhidden", run step 3, just print onconfigchanged

Onconfigurationchanged () à

8) Change the android:configchanges= "orientation" of step 5 to

Android:configchanges= "Orientation|keyboradhidden", run step 4

Onconfigurationchanged () à

Onconfigurationchanged () à

Summarize:

1) When you do not set the activity's android:configchanges, the screen will call each life cycle again, and it will run once when the screen is cut horizontally. It runs two times when you cut the vertical screen.

2) When you set the activity's android:configchanges= "orientation", the screen will call each life cycle again, cut the horizontal screen, the vertical screen will only run once, But the vertical screen last more than one onconfigurationchanged ()

3) When setting the activity's android:configchanges= "Orientation|keyboardhidden", the screen will not call each life cycle again, just run the onconfigurationchanged () , horizontal screen once, vertical screen two times

Then summarize the life cycle of the activity:

1) The activity's life cycle will not change when the activity generates an event popup toast and Alertdialog

2) When activity executes, press the home button (as if it is completely covered)

Onsavainstancestateà

Onpauseà

Onstopà

Onrestartà

Onstartà

Onresumeà

3) is not completely covered, just loses focus:

Onpauseà

Onresumeà

16. How do I publish the SQLite database (. db file) with the apk file?

A: You can copy the. db file to the Res AW folder in Eclipse Androidproject. All files in the Res AW folder are not compressed. This allows you to extract the files in the folder directly.

Ability to copy. db files to the Res AW folder

17. How do I open a database file in the Res AW folder?

A: You cannot open the database file in the Res AW folder directly in Android. You need to copy the file to a folder in your phone's memory or SD card when the program first starts, and then open the database file. The basic method of replication is to use the Getresources (). Openrawresource method to obtain the InputStream object of a resource in the Res AW folder, and then write the data from that InputStream object to the corresponding file in the other folder.

In the Android SDK, you can use the Sqlitedatabase.openorcreatedatabase method to open the SQLite database file in a random folder.

What kinds of XML-parsing classes are in 18.android? What kind of official recommendation? and their principles and differences:

A: There are three main ways of parsing XML, SAX, DOM, pull. Conventional development on the PC we use the DOM relatively easily. But some performance-sensitive databases or phones are mostly sax-only, and sax reads are unidirectional. Advantages: No memory space, parsing properties convenient. However, the disadvantage is that it is not very convenient to handle nested multiple branches.

And Dom Way will put the entire XML file into memory, where the Android Development network to remind everyone that the method in the lookup aspect can and XPath very good combination of assumptions data is not very large recommended use, and pull is often used in J2ME for node processing is better, similar to the sax way, The same is very memory-saving. In J2ME we often use the Kxml library to parse.

The difference between 19.DDMS and TraceView?

A: DDMS is a program run viewer, in which you can see threads and stacks and other information, TraceView is a program Performance analyzer

20. Talk about the IPC mechanism of Android:

A: IPC is the abbreviation for internal process communication and is a resource for sharing named pipes. The IPC mechanism in Android is designed to enable interaction between activity and service at any time. So the mechanism in Android. Only applies to the communication between activity and service. Similar to remote method calls. An interview similar to the C/S mode.

Define the IPC interface by defining the Aidl interface file. The Servier end implements the IPC interface. The client side invokes the IPC interface local agent.

What 21.NDK is:

A: The NDK is a collection of a range of tools

The NDK provides a range of tools. Enables developers to quickly develop a dynamic library of C + +. And can take the initiative to make so and Java applications into APK package

The NDK integrates a cross compiler and provides the difference between the corresponding MK file and the isolated CPU, platform, etc., and developers simply need to change the Mk file to create a

22. Describe the system architecture of Android:

A: The Android system architecture is divided from bottom to top for the Linux kernel layer, the execution library, the application framework layer, and the application layer.

Linux kernel layer: Responsible for the hardware driver, network, power, system security, memory management and other functions.

Execution libraries and androidruntion: Execution libraries: That is, the C + + function library section, most of which are open source function libraries. For example WebKit, the library is responsible for the implementation of the Android Web browser, such as the standard C function library libc, OpenSSL, SQLite, etc., of course, also includes support game development of 2DSGL and 3dopengles. There is a mediaframework framework in multimedia to support the playback and display of various audio-visual and graphic files. Many multimedia file formats such as MPEG4, H, MP3, AAC, AMR, JPG, and PNG. Androidruntion is responsible for interpreting and executing bytecode in the generated Dalvik format

Application Architecture: Java application developers are primarily using this layer of packaged APIs for high-speed development.

Application layer: This layer is the Java application layer, Android built-in GoogleMaps, e-mail, IM, browser, etc., are in this layer, Java developers work out the program is also in this layer, and built-in applications have an equal status. Ability to invoke built-in applications. can also replace built-in applications

What are the 23.Activity and task startup modes, and what do they mean in detail?

A: In an activity, there are multiple calls to startactivity to start another activity, to just generate an activity instance. Ability to set startup mode.

One activity has four startup modes: Standed,signletop,singletask,singleinstance

Standed: Standard mode, a call to the StartActivity () method produces a new instance.

Singletop: Suppose there is already an instance at the top of the activity stack. Does not produce new instances, but merely invokes the newinstance () method in activity.

Assuming that it is not at the top of the stack, a new instance is generated.

Singletask: this instance is generated in a new task. This will be used for each subsequent call. Not going to produce a new instance.

SingleInstance: This is basically the same as singletask, with only one difference: the task in which the activity instance is located in this mode. You can only have this activity instance, no other instances

The role of the 24.Application class:

Answer: The first sentence in the API is:

Base class for those who need to maintain global application state

Assuming that you want to use global variables throughout your application, static variables are often used in Java. Public type, while in Android it is assumed that this global variable does not conform to Android's framework architecture. But being able to use a more elegant way is to use the application context.
First, you need to rewrite application, the main rewrite inside the OnCreate method, is the time of creation. Initializes the value of the variable. The variable can then be manipulated in various files throughout the application.
When you start application, a PID is created. That is, the process ID. All the activity will be executed on this process. Then we initialize the global variables when the application is created, all the activity of the same application can fetch the values of these global variables, in other words, we change the values of these global variables in one activity, Then the value of the other activity in the same application will change.

25. Explain when Onsaveinstancestate () and Onrestoreinstancestate () are called:

A: Activity Onsaveinstancestate () and onrestoreinstancestate () are not life cycle methods. They are different from life cycle methods such as onCreate (), OnPause (), and they are not necessarily triggered. Onsaveinstancestate () is called when an activity is destroyed by the system when an application encounters an unexpected situation (such as insufficient memory, the user presses the home key directly). However, when the user actively destroys an activity, such as pressing the return key in the app, Onsaveinstancestate () will not be called. Because in such a case. The behavior of the user determines the state of the activity that does not need to be saved.

usually Onsaveinstancestate () is only suitable for storing some transient state, while OnPause () is suitable for persisting data.



In addition, when the orientation of the screen has changed. The activity is destroyed and created again, assuming you want to cache some data before the activity is destroyed, and restore the cached data after the activity is created again. Ability to rewrite activity's onsaveinstancestate () and Onrestoreinstancestate () methods.

The life cycle of a 26.android service? Which method can be called multiple times:

A: 1) The life-cycle approach associated with starting a service using the Context.startservice () method

OnCreate (), OnStart (), OnDestroy ()

OnCreate () This method is called when the service is created, and the method is only called once, and the service is created only once, regardless of how many times the StartService () or Bindservice () method is called.
OnStart () The method is only invoked when the service is started by using the Context.startservice () method. This method is called when the service starts executing. The StartService () method is called multiple times although the service is not created more than once, but the OnStart () method is called multiple times.
OnDestroy () This method is called when the service is terminated.


2) Life-cycle methods related to initiating services using the Context.bindservice () method
OnCreate (), Onbind (), Onunbind (), OnDestroy ()

Onbind () The method is only invoked when the service is started by using the Context.bindservice () method.

This method is called when the caller and the service are bound, and the Context.bindservice () method is called multiple times when the caller is tied to the service and does not cause the method to be called more than once.
Onunbind () The method is only invoked when the service is started by using the Context.bindservice () method.

This method is called when the caller and the service are unbound.


Suppose you first start the service with the StartService () method, and then call the Bindservice () method to bind to the service, and then call the Unbindservice () method to unbind. The last call to the Bindservice () method binds to the service again. The life cycle methods that are triggered are as follows:
OnCreate ()->onstart ()->onbind ()->onunbind () [the overloaded method needs to return true]->onrebind ()

The life cycle of the 27.android broadcast:

Answer: 1) There is only one callback method in the broadcast receiver lifecycle:
void OnReceive (Context curcontext, Intent broadcastmsg)
When the receiver receives a broadcast message, Android invokes Onreceiver () and passes it to a intent object, which carries the broadcast message. We feel that only when this mode is run. Broadcast receiver is active. When this method returns, it terminates.

This is the life cycle of broadcast receiver.


2) because the life cycle of the broadcast receiver is very short, a process with an active broadcast receiver is protected to avoid being killed, but don't forget that Android will kill any process that carries components that are no longer active at random times. So it is very likely to cause this problem.


3) The solution to the above problem with a service to complete the work, Android will feel that process (the service is in the process) is still in the active component.

28.android view. Differences in Surfaceview,glsurfaceview:

A: Surfaceview is a display class derived from the view base class, with direct subclasses of Glsurfaceview and Videoview, which shows that GL and video playback and camera cameras are generally used Surfaceview
The most essential difference between surfaceview and view is that. Surfaceview is able to draw the screen again in a new, separate thread and view must update the screen in the main thread of the UI.


Updating the screen in the main thread of the UI can cause problems. For example, if you update the screen for too long, your main UI thread will be blocked by the function you are drawing. Then you will not be able to respond to keystrokes, touch screens and other messages.
When using Surfaceview because it is updating the screen in a new thread, it will not clog your UI main thread. But this also brings up another problem, namely, the synchronization of events.

For example, if you touch the screen, you need to surfaceview in the thread processing, it is generally necessary to have an event queue design to save touch event, which is slightly more complicated, because it involves thread synchronization.



So based on the above. According to the game features. Generally divided into two categories.

1) Passive update screen. For example, chess. It's good to use view like this. Because the screen update is dependent on OnTouch to update. Ability to use invalidate directly. Because of this, this touch and the next touch will take a long time, no impact.

2) Automatic Update.

For example, a person has been running. This requires a separate thread. People constantly redraw the state to avoid clogging the main UI thread. Obviously the view is inappropriate. Must be surfaceview in order to control.

Android face Test is not just an interview is a good learning

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.