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

Source: Internet
Author: User
Tags sqlite database

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. Whether the application is on the same concept:

Answer: DVM is a dalivk virtual machine. Each Android application executes in its own process and 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 playing a good 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 the new message into the MessageQueue. or receive messages from Looper (taken out of 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 view in Android. Use to distinguish between different application situations.

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 to update the UI, and then your handler (the ability to use anonymous inner classes) to process the message (because anonymous inner classes can access the parent class variable, you can directly invoke the Invalidat in the View object E () method). That is, a message is created and sent on a new thread. The message is then captured and processed in the main thread.

3). Use multithreading and double buffering

Surfaceview is a subclass of view in Android, and she also implements double buffering at the same time.

You can define a subclass of her and implement the Surfaceholder.callback interface.

Because the Surfaceholder.callback interface is implemented. The new thread will not need android.os.Handler to help. Surfaceholder the Lockcanvas () method can lock the canvas, draw a new image after it is called unlockcanvasandpost (canvas) to unlock (display), or more convenient.

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 main part of the application, and all 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 files to describe the interface, when used can be very convenient to introduce, of course, how you know more about Android, you will be able to think of Android can also use javascript+ HTML, and so on as the view layer. Of course, there is a need for communication between Java and JavaScript, and fortunately, Android provides a convenient communication implementation between them.

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. 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 processed in the model, of course, business calculations and other operations must be placed in the layer.

6.Activity Life cycle:

A: onCreate: Create the interface here, do some data initialization work

OnStart: To this step becomes user visible non-interactive

Onresume: Becomes interactive with the user. (The activity stack system manages the top of these activity in 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 already know, should be here to save some of your data, because this time your program's priority is reduced, it is possible to be recalled by the system. Save the data 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. It could be the outside class calling 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 document; a sqlite;contentprovider. Internet

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? What kind of data can I work with?

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

12. Multiple browsers are installed on the system. Can I specify a browser to access the specified page ? Please explain the original:

A: Take the number of references 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. So. In the program it is very important to design the response performance. Such The system does not display 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. Especially. 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-consuming 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.

Designing 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 timeout 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 intentreceiver of running time means it should: do small, trivial work in the background. such as Save settings or register a notification. Like other methods that are called in the main thread, applications should avoid time-consuming operations or computations in Broadcastreceiver, but they 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, as it will create 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.

Suppose your application is working in the background in response to user input. The ability to show the progress of the work (ProgressBar and progressdialog are very useful for such a situation). 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 of these cases. You should always show the progress you're making so that the user doesn't feel 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 Androidmanifest.xml. Add the activity to android:configchanges= "orientation", run step 4, and find that the same information is not printed, 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, cut the horizontal screen will run once, cut the vertical screen will run two times.

2) When you set the activity's android:configchanges= "orientation", the screen will call each life cycle again, and it will only run once when you cut the horizontal screen and the vertical screen. 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 on Android, but 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. General development on the PC we use the DOM relatively easy, but some performance-sensitive database or mobile phone is the main use of 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. The DOM approach will load the entire XML file into memory, where the Android development network reminds everyone that the method can be very good with XPath in terms of finding the data volume is not very recommended to use. And pull is often used in J2ME for node processing is better, similar to the Sax way, the same very memory savings. In J2ME we often use the Kxml library to parse.

The difference between 19.DDMS and TraceView?

A: DDMS is a program that runs the viewer, where you can see information such as threads and stacks. 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 is only suitable for 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 to enable developers to quickly develop C + + dynamic libraries and to make their own active use of so and Java applications as APK packages

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 Library and androidruntion: Execution Library: That is, the C + + function library section, mostly open-source libraries, such as WebKit, which is responsible for the implementation of the Android Web browser. For example, the standard C function library libc, OpenSSL, SQLite and so on, of course, also contains support game development of 2DSGL and 3dopengles, in the multimedia has mediaframework framework to support a variety of video and graphics file playback and display, such as MPEG4, Many multimedia file formats, including 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 application layer of java. Android built-in GoogleMaps, email, IM, browser, etc., are in this layer. The Java Developer program is also in this layer. and has an equal status with the built-in applications. 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?

Answer: In an activity. There are several calls to startactivity to start the activity, and to generate only one activity instance, you can set the 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: Assuming that there is already an instance at the top of the activity stack, it does not produce a new instance, 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 will be generated in a new task, which will be used for each subsequent invocation and will not produce a new instance.

SingleInstance: This is basically the same as Singletask. There is only one difference: in the task where the activity instance is in this mode, only the activity instance can be found, 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, in Java it is common to use static variables, public types, and in Android it is assumed that this global variable does not conform to the Android framework, but a more elegant way to use application Context


First you need to rewrite application. The main rewrite inside of the OnCreate method is to initialize the value of the variable when it is created. The variable can then be manipulated in various files throughout the application.
When application is started, a PID, the process ID, is created, and all activity is executed on this process. Then we initialize the global variables when the application is created. All activity of the same application is able to fetch the values of these global variables. Other words. When we change the values of these global variables in one activity, the values in the other activity in the same application 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 (). They are not bound to be 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). But when the user is active to destroy an activity. For example, by pressing the return key in the application, Onsaveinstancestate () will not be called. As a result of this, the user's behavior determines that there is no need to save the activity State.

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

Other than that. When the orientation of the screen changes, 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, regardless of how many times the StartService () or Bindservice () method is called. The service is also created only once.
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. When the caller and the service have been bound, multiple calls to the Context.bindservice () method do 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 start the service with the StartService () method, then call the Bindservice () method to bind to the service, call the Unbindservice () method to unbind, and finally call the Bindservice () method to bind 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 broadcast receiver is active only when this mode is run, and it terminates when this method returns. This is the life cycle of broadcast receiver.


2) because broadcast receiver has a very short life cycle, a process with an active broadcast receiver is protected to avoid being killed. But don't forget that Android will kill the processes that carry the components that are no longer active at random moments, so it's 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.

Differences in 28.android View,surfaceview,glsurfaceview:

A: Surfaceview is a display class derived from the view base class, with the direct subclasses having Glsurfaceview and Videoview. Be able to see 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, you have been updating the screen for too long. Then 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.

Therefore, based on the above, according to the game characteristics, generally divided into two categories.

1) Passive update screen.

For example, chess, such a view is good. Since the screen update is dependent on OnTouch to update, it is possible to use invalidate directly. Because of this, there is no effect on the comparison between this touch and the next touch.

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 question is not just an interview is a good learning

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.