63.Android question Selection (turn)

Source: Internet
Author: User
Tags sqlite database

1.Android the process of DVM and the process of Linux, whether the application process is the same concept:

A: DVM is a dalivk virtual machine. Each Android application runs in its own process and has a DALIVK virtual machine instance. And each DVM is a process in Linux. So it can be considered 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, which 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, similar to the film.

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, and you need to distinguish between different applications when using it. 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 a wish to redraw the UI when the view changes. You only need to explicitly invoke the Invalidate () method in the View object in the activity. The OnDraw () method of the view is automatically called.

2). Use multithreading and do not use double buffering

This situation requires a new thread to be opened, and the new thread will not have access to the View object. Forced access 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 (you can use anonymous inner classes) to process the message (because the anonymous inner class 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, and then captured and processed in the main threads.

3). Use multithreading and double buffering

Surfaceview is a subclass of view in Android, and she also implements double buffering. You can define a subclass of her and implement the Surfaceholder.callback interface. With the implementation of the Surfaceholder.callback interface, the new thread does 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 MVC mode. 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 in that layer.

2 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.

3 Controller object: is based on the user's input, control the user interface data display and update model object state of the part of the controller more important a navigation function, want to use the user to start the relevant events, to M oh got 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, the use of the time can be very convenient to introduce, of course, how you learn 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.

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: Become interactive with the user, (in the activity stack system through the stack to manage the top of these activity, run out of pop-up stack, then 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 above description already know, should be here to save some of your data, because this time your program has a lower priority, it may be recalled by the system. The data that is stored here should be in

OnStop: becomes invisible and is 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. Turn activity into a window:

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, where manifest.xml defines the activity, add a sentence:

Android:theme= "@android: Style/theme.dialog"
If the effect is translucent:

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

Five types of layouts 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:

A: sharedpreferences; 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 do I work? What types of data can be processed?

Answer: Aidl (androidinterface Definition Language) Android Interface Description 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: Pass the parameters through the direct send URI, 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, if 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 apps and how best to build applications to avoid ANR.
Android applications are typically run on a separate thread (for example: main), which means that what your application does will cause the ANR dialog box to be thrown if it takes a long time in the main thread. Because your application does not give you the opportunity to handle input events or intent broadcasts.

Therefore, any adapting running on the mainline thread do as little as possible. 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-consuming computations such as changing the bitmap size, should be done in the thread of the Strand (or, in the case of database operations, through asynchronous requests). However, it does not mean that your main thread is blocking 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 complete. Designing your application in this 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. This practice should be emulated in other threads that display the UI because they are affected by the same timeout.

The special limitation of intentreceiver execution time means it should: do small, trivial work in the background, such as saving settings or registering 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 (because the Broadcastreceiver life cycle is short), instead, If a time-consuming action is required to respond to intent broadcasts, the application should start a service. Incidentally, 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. If 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 in which users can sense blocking, and here are some tips to avoid ANR and help make your application look responsive.

If your application is working behind the scenes in response to user input, you can show the progress of your work (ProgressBar and progressdialog are useful for this scenario). In particular the game, in the sub-thread to do mobile computing. If your program has a time-consuming initialization process, consider displaying a splash screen or quickly displaying the main picture and populating the information asynchronously. In both cases, you should display the progress you are making in order to prevent users from thinking that the program is frozen.

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

A: such as a null pointer can lead to forceclose, you can see Logcat, and then find the corresponding 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) Run the activity and get the following information:

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) Modify the Androidmanifest.xml, add the activity android:configchanges= "orientation", perform step 3

Onsaveinstancestate ()

OnPause ()

OnStop ()

OnDestroy ()

OnCreate ()

OnStart ()

Onrestoreinstancestate ()

Onresume ()

6) Modify the Androidmanifest.xml, add the activity android:configchanges= "orientation", perform step 4, and find that the same information will not be printed again. 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", perform step 3, just print onconfigchanged

Onconfigurationchanged ()

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

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

Onconfigurationchanged ()

Onconfigurationchanged ()

Summarize:

1) When the activity's android:configchanges is not set, the screen will recall each life cycle, and will be executed once when the screen is cut, and will be executed two times when the vertical screen is cut.

2) When you set the activity's android:configchanges= "orientation", the screen will recall each life cycle and will only be executed 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 recall each life cycle, only the onconfigurationchanged () will be executed, 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 the activity is running, press the home key (the same as the full cover)

Onsavainstancestateà

OnPause

OnStop

Onrestart

OnStart

Onresume

3) not fully covered, just lose focus:

OnPause

Onresume

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

A: You can copy the. db file into the res AW directory in Eclipse Android project. All files in the Res AW directory are not compressed so that the files in that directory can be extracted directly. You can copy the. db file into the res AW directory

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

A: You cannot open a database file in the Res AW directory directly on Android, but you need to copy the file to a directory 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 for a resource in the Res AW directory, and then write the data in the InputStream object to the corresponding file in the other directory. The Sqlitedatabase.openorcreatedatabase method can be used in the Android SDK to open SQLite database files in any directory.

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 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.

What is the difference between 19.DDMS and TraceView?

A: DDMS is a program execution viewer, where you can see information such as threads and stacks, and 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 allow interaction between activity and service at any time, so the mechanism in Android is only suitable for communication between activity and service, similar to the remote method invocation, similar to the C/S mode access. Define the IPC interface by defining the Aidl interface file. The Servier end implements the IPC interface, and 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 help developers quickly develop C + + dynamic libraries and automatically play so and Java apps as apk packages

The NDK integrates the cross compiler and provides the corresponding MK file and the isolated CPU, platform and other differences, developers can simply modify the Mk file to create a so

22. Describe the Android system architecture:

A: The Android system architecture is divided from bottom to top for the Linux kernel layer, the runtime, 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.

Run-Time Libraries and androidruntion: Runtime: the C + + function library section, most of which are open source libraries, such as WebKit, which is responsible for the operation of the Android Web browser, such as the standard C function library libc, OpenSSL, SQLite, etc. , of course, also includes support for game development of 2DSGL and 3dopengles, Multimedia has a mediaframework framework to support a variety of audio-visual and graphics file playback and display, such as MPEG4, H. V, MP3, AAC, AMR, Many multimedia file formats, such as 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 rapid development.

Application layer: This layer is the Java application layer, Android built-in GoogleMaps, email, IM, browser, etc., are in this layer, Java Developer Program is also in this layer, and the built-in application has an equal position, can call the built-in application, You can also replace the built-in application

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

A: In an activity, there are multiple calls to startactivity to start another activity, in order to generate only one activity instance, you can set the startup mode.

One activity has four startup modes: Standard,singletop,singletask,singleinstance

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

Singletop: If an instance already exists at the top of the activity stack, it does not produce a new instance, but simply invokes the newinstance () method in the activity. If 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 this mode the activity instance is in the task, only the activity instance, cannot have 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

If you want to use global variables throughout your application, you typically use static variables, public types in Java, and if you use such global variables in Android that do not conform to Android's framework architecture, but you can use a more elegant way to use application Context
First you need to rewrite the application, the main rewrite inside the OnCreate method, that is, when creating the value of the initialization variable. 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 run 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 not necessarily triggered, unlike life cycle methods such as onCreate (), OnPause (). 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 () is not called. Because in this case, the behavior of the user determines that there is no need to save the activity State. usually Onsaveinstancestate () is only suitable for storing some temporary state, while OnPause () is suitable for persisting data.

Additionally, when the orientation of the screen changes, the activity is destroyed and recreated, if you want to cache some data before the activity is destroyed, and restore the cached data after the activity is recreated. The Onsaveinstancestate () and Onrestoreinstancestate () methods of the activity can be rewritten.

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

A: 1) life-cycle methods related to starting services with 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 with the Context.startservice () method. This method is called when the service starts running. 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 starting services with the Context.bindservice () method
OnCreate (), Onbind (), Onunbind (), OnDestroy ()

Onbind () The method is only invoked when the service is started with 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 with the Context.bindservice () method. This method is called when the caller and the service are unbound.
If you start the service with the StartService () method, and then call the Bindservice () method to bind to the service, then call the Unbindservice () method to unbind it, and finally call the Bindservice () method to bind to the service again. The triggering life cycle method is 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 think that broadcast receiver is active only when this method is executed, and it terminates when it returns. This is the life cycle of broadcast receiver.


2) because broadcast receiver has a short life cycle, 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 any time, So it is likely to cause this problem.


3) The solution to the above problem is to use a service to do this, and Android will assume that the process (the service's process) still has the active component.

The difference between 28.android View,surfaceview,glsurfaceview:

A: Surfaceview is a display class derived from the view base class, with direct subclasses of Glsurfaceview and Videoview, and you can see that GL and video playback and camera cameras are generally used Surfaceview
The essential difference between surfaceview and view is that Surfaceview is able to redraw the screen 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 may cause problems, such as the time you update the screen too long, and 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 does not block 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 characteristics of the game, generally divided into two categories.

1) Passive update screen. Like chess, this is good with view. Because the screen update is dependent on OnTouch to update, you can use the invalidate directly. Because of this, the touch and the next touch will take longer and will not have an impact.

2) Proactive updates. Like a man running all the time. This requires a separate thread to redraw the human state continuously, avoiding blocking the main UI thread. So obviously the view is not suitable, need surfaceview to control.

63.Android question Selection (turn)

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.