Follow Finddreams Blog: http://blog.csdn.net/finddreams/article/details/44219231
In the hot season of job hopping, the most frequently tested pen test in Android interview, prepare for the next job, this is the basic part of Android:
1. What are the four components of Android? Role and application scenarios?
The four components of Android are activity,service,broadcastreceiver and contentprovider;
Activity:
In the literal sense, activity is the meaning of activities. An activity is usually presented as a visual user interface, a window into which the Android program interacts with the user, and is the most basic and complex component of the Android component. From a visual perspective, an activity occupies the current window, responds to all window events, has controls, menus, and other interface elements. From the internal logic, the activity needs to do a lot of persistence in order to maintain the various interface states, but also need to manage the life cycle, and some of the jump logic.
Service
Service is a component running in the background, and in a sense, the service is like an activity without an interface. They are close to many of the Android concepts, encapsulating a complete functional logic implementation, accepting upper-level instructions, completing related events, and defining the intent to be accepted to provide synchronous and asynchronous interfaces.
Broadcastreceiver
Broadcast receivers, without performing any tasks, broadcast is a widely used mechanism for transferring information between applications. The broadcastreceiver is a type of component that filters and responds to the broadcast being sent. Broadcast Receiver does not contain any user interface. However, they can initiate an activity in response to the received information, or notify the user via Notificationmanager. There are several ways to make users aware of new notifications: flashing background lights, vibrating devices, making sounds, and more. Typically, the program places a persistent icon on the status bar where the user can open the icon and read the notification message. Another important concept in Android is intent, if intent is an abstract description of actions and behaviors, responsible for message passing between components. Then the broadcast receiver component provides a mechanism to broadcast intent as a message and to react to it by all programs that are interested in it.
Content Provider
That is, content providers, as the only way to share data between applications, the main function of the Provider is to store and retrieve data and provide access data to other applications.
For applications, the underlying data can also be encapsulated into contentprovider, which effectively masks the details of the underlying operation and keeps the program well-extended and open. Android offers some of the main data types of contentprovider, such as audio, video, images, and personal contacts. Some Android-provided ContentProvider can be found under the Android.provider package. These contentprovider can be obtained to query the data they contain, assuming, of course, that the appropriate Read permission has been obtained. If we want to expose our application's data, we can create our own Content Provider interface.
2. What are the types of animations in Android, and what are their characteristics and differences?
Two kinds, one is tween animation, and another is frame animation. Tween animations, which enable the view component to move, zoom in, zoom out, and create transparency, another frame animation, a traditional animation method, is implemented by sequential playback of a well-arranged picture, similar to a movie.
3. What happens when the backstage activity is collected by the system? How do I save the current state before being reclaimed by the system?
When an activity is pause or stop, the object of the activity is actually kept in memory, so the information in the activity (Member and state information) can be retrieved again.
If the system destroys the activity object in order to defragment the memory, the system cannot simply restore the previous activity object and its status information as it is.
A method is provided in activity: Onsavedinstancestate (Bundle obj). When the system destroys an activity, the activity's state information is stored in the Bundle object in the form of a key-value pair.
When the activity is first started, the bundle object is empty, null. If the activity is destroyed by the system and the user is going back to see it, the system invokes the activity's OnCreate method and passes the bundle object past.
4. Please describe the activity life cycle.
5. How to set an activity to the window's style.
Where activity is defined in Androidmanifest.xml a word android:theme= "@android: Style/theme.dialog" or "android:theme=" @android: Style /theme.translucent "becomes translucent.
6. What are the pros and cons of registering a broadcast in several ways?
There are two kinds, one is code dynamic registration:
Generate broadcast Processing
Smsbroadcastreceiver = new Smsbroadcastreceiver ();
Instantiate the filter and set the broadcast to be filtered
Intentfilter intentfilter = new Intentfilter ("Android.provider.Telephony.SMS_RECEIVED");
Register a broadcast
BroadCastReceiverActivity.this.registerReceiver (Smsbroadcastreceiver, Intentfilter);
One is to configure the broadcast in Androidmanifest.xml
<!--broadcast registration--> <receiver android:name =; <intent-filter android:priority = "a" ; <action android:name = "Android.provider.Telephony.SMS_RECEIVED" /> </intent-filter ; </receiver ;
The differences between the two types of registrations are:
1) The first is not a resident broadcast, which means that the broadcast follows the program's life cycle
2) The second type is resident, which means that when the application is closed, the program is automatically run by the system call if there is a message broadcast.
There are two methods of registering, one is static registration and one is dynamic registration.
Dynamic Registration Advantages: In the Android broadcast mechanism, the priority of dynamic registration is higher than the static registration priority, so if necessary, we need to dynamically register the broadcast receiver.
Static Registration Advantages: Dynamic registration of the broadcast receiver also has a feature, that is, when the Activity used to register is turned off, the broadcast will expire. It also reflects the advantage of static registration, that is, there is no need to worry about whether the broadcast receiver is turned off, as long as the device is turned on and the broadcast receiver is open.
What are the advantages of 7.IntentService?
Normal service, default running in UI main main thread
This is the service class with asynchronous processing,
Method of asynchronous processing onhandleintent ()
Onhandleintent () processing time-consuming operations
Android's process processor will now try to kill you without killing
8. What is the life cycle of the activity when switching between screens?
1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice
2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
3, set the activity android:configchanges= "Orientation|keyboardhidden", the screen will not recall the various life cycle, will only execute onconfigurationchanged method
9. How do I publish the SQLite database (dictionary.db file) with the apk file? How do I open a database file in the res aw directory?
Answer: To copy the Dictionary.db file to the Res AW directory, you cannot open the 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. In the Android SDK, you can use the Sqlitedatabase.openorcreatedatabase method to open SQLite in any directory;
what information is primarily contained in the 10.androidmanifest.xml file
Describes the Java package for the application, which is the unique identity of the application;
Describes the components of an application: which activity,service,broadcast receiver and content provider comprise the application;
Declare the permissions that an application must have to access protected parts of the API, and to interact with other applications;
Declare the minimum version level of the Android API required by your application, such as 1.0,1.1,1.5;
Manifest: Root node that describes all the contents of the package.
Uses-permission: Ask for the security license you need to give your package a normal operation.
Permission: A security license is declared to limit which programs can be components and features in your package.
Instrumentation: Declares the code used to test this package or other Packages directive component.
Application: Contains the root node of the application level component declaration in the package.
Activity:activity is the primary tool for interacting with users.
Receiver:intentreceiver enables the application to obtain data changes or actions that occur even if it is not currently running.
Service:service is a component that can run at any time in the background.
Provider:contentprovider is a component used to manage persisted data and publish it to other applications.
11.Android Data storage method
I. Sharedpreferences mode: It is a mechanism provided by Android to store some simple configuration information in an XML format that stores data in the device. Can only be used within the same package and cannot be used between different packages.
Two. file storage mode/data/data/package name/files memory inside
/context.openfileinput (name) is private access by default
Three. SQLite database mode: SQLite is a standard database with Android, it supports SQL statements, it is a lightweight embedded database.
Four. Content provider: used primarily for data exchange between applications, enabling other applications to save or read the various data types of this content provider.
Five. Network storage: Upload (store) and download (obtain) The data we store in cyberspace by providing our storage space on the network.
introduction of five common layouts in 12.Android
Framelayout (Frame layout): Starts the layout from the upper left corner of the screen, overlays the display, and actually applies the player's pause button.
LinearLayout (Linear layout): can be divided into vertical layout, horizontal layout;
Absolutelayout (Absolute layout): Specify the position of the element with x, y coordinates;
Relativelayout (relative layout): The relative layout can be understood as an element as a reference, to locate the layout way.
Tablelayout (table layout): Table layout is similar to table in HTML. Every tablelayout has a table row Tablerow,tablerow inside can define each element in detail, set his alignment android:gravity= "".
Each layout has its own appropriate way, and these five layout elements can be nested within each other to make an aesthetically pleasing interface.
four startup modes in 13.Activity? , the way activity and task are started, what they mean is specific
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 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.
length unit in 14.Android detailed
You can use a DP or SP if you set properties that represent length, height, and so on. However, if you set the font, you need to use the SP. The DP is not density-independent, and the SP is not related to scale, except for density. If the screen density is 160, then the DP and SP and PX are the same
Of 1DP=1SP=1PX,
That is, if the DP and SP are used, the system will automatically convert based on the change in screen density
PX: Indicates the actual pixel of the screen
In: represents inches, which is the physical size of the screen. Equal to 2.54 centimeters per inch.
What are some of the classes that parse the L XML in 15.android,,, which is officially recommended? and their principles and differences.
DOM parsing
Benefits:
1.XML trees are fully stored in memory, so you can modify their data and structure directly.
2. Any node in the XML tree can be accessed at any time through the parser. The API for the
3.DOM parser is relatively simple to use.
Cons: If the XML document is larger, reading the document into memory is very expensive for system resources
? Sax parsing
Benefits:
Sax requires less memory because it lets the developer decide what label to work on. Especially if the developer only needs to work with some of the data contained in the document, Sax has a better ability to scale.
Cons:
XML parsing in SAX requires sequential execution, making it difficult to access different data in the same document. In addition, the parsing coding process based on this approach is also relatively complex
? Xmlpull parsing (officially recommended) The
Android SDK provides xmlpull api,xmlpull and sax, which is a stream-based action file, and then callback the developer-written handler based on the node event. Because it is based on stream processing, Xmlpull and Sax Compare sections
about memory resources and do not show all nodes in memory as Dom does in the form of oak. Xmlpull is more concise than sax and does not need to scan through the entire stream.
16.ListView Optimization Scheme
(1), if the custom adapter, then in the GetView method to consider the method passed in the parameter contentview is null, if it is null to create Contentview and return, if not NULL is directly used. In this method, create as few view as possible.
(2), to Contentview set tag (Settag ()), passed in a Viewholder object, used to cache the data to be displayed, can achieve the effect of asynchronous loading of image data
(3) If the ListView needs to display a lot of item, it is necessary to consider paging load. For example, to show a total of 100 or more times, we can consider loading 20 first, and so on when the user pulls to the bottom of the list, then to load the next 20.
(4) Do not load pictures when sliding quickly
(5) If you have a picture in your custom item, you need to process the picture (reduce the memory of the image)
1. Edge compression of the image 2. Use the option class to save the image size 3. Avoid real-time zooming of pictures, preferably zoom to view size beforehand
(6) Try to avoid using threads in the ListView adapter, because threads are the primary cause of memory leaks because the thread's life cycle is not controllable.
the role of intent in 17.Android
In an Android application, it is primarily composed of components (activity,service,contentprovider,etc.) In the communication between these components, the Intent assists the completion.
Intent is responsible for the action of one operation in the application, the action involves the data, the additional data
Description, Android is responsible for locating the corresponding component, passing the Intent to the calling component, and completing the component invocation, based on the description of this Intent. Intent is where the decoupling between the caller and the callee is implemented.
There are two ways, one is display matching, one is implicit matching;
Display: Explicitly specify the activity to jump to, or service, etc.;
Implicit: implicit matching, the first to match the Intent of several values: Action,category, data/type,component if filled with componet is this form a display match.
1. If you fill in the action, if there is a program in the manifest.xml of an Activity in the Intentfilter segment defined contains the same action then this Intent will match this target Action, if the The type,category is not defined in the filter section, then the Activity is matched. But if you have more than two programs in your phone, a dialog box will pop up to show you the message.
2,data/type, you can use URIs as data, such as URI uri = Uri.parse (http://www.google.com);
Intent i = new Intent (Intent.action_view,uri), cell phone Intent distribution process, according to the http://www.google.com scheme to determine the data type of the cell phone brower Can match it, in the Brower manifest.xml in the Intenfilter in the first Action_view Action, can also handle http: the type;
3, as for classification category, generally do not go to set it in Intent, if you write Intent receiver, in Manifest.xml Activity Intentfilter contains Android.category.DEFAULT So that all Intent that do not set the category (Intent.addcategory (String c);) will match this category.
4,extras (additional information), is a collection of all other additional information. You can use extras to provide extended information for your component, such as, if you want to perform the "Send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending component.
18. How do I exit Activity? How do I exit safely?
For a single Activity application, the exit is simple, just finish ().
Of course, you can also use KillProcess () and System.exit () methods.
For programming convenience, it is best to define an Activity base class to handle these common problems.
1. Record Open activity:
Each activity is opened and recorded. When you need to exit, close each Activity.
2. Send specific broadcasts:
When you need to end the app, send a specific broadcast, and after each Activity receives the broadcast, it's off.
Android Development interview by--2. Common Android Basic Pen questions