Android ----------------- answer questions

Source: Internet
Author: User
Tags call back website server

Android ----------------- answer questions



1. What are the parsing methods of XML? What is the execution process of each parsing method?

Set XML to:BcC1


Dom SAX Pull


2.BcC1What should they look like in a tree

The root node is above

The subnode and text are listed below



3. There are three existing activities: A1, A2, and A3. How can we achieve A1 to start A2? After A2 starts A3, A3 can directly return the result to A1? Are two methods available?

Inflate

1 A1-"A2-" A3 A2 finish ()

2 A2 does not go back to the station? (How) A2 starts A3


3.2. there are currently three activities, A1, A2, A3. Now A1 starts A2 and A2 returns complex data to A1. After A1 receives data, it starts A3, what should I do if I transfer the corresponding data for operations?

StartACTIVITYForRessult ()

OnActivity Result ()-> A3 Intent Bundle



4. Set up the existing app App1 and App2, where App2 is a book resource application, App1 is a reader application, and App1 needs to obtain the book data of App2. How should it be used? Can I use App1 to delete two types of book data?

A2 implements ContentProvider, which provides addition, deletion, modification, and query, and delete ()


5. What is the push principle of Android GCM?


The backend of the client has the Service. Google that receives messages to push the server.

The relationship between the customer ticket and the server is persistent. To receive the pushed msg! At the same time, google's server,

Provides backend management interfaces. Sends information to a specified device.


Certificate ------------------------------------------------------------------------------------------------------------------------------------------------


Use the GCM Service (Google Cloud Messaging)


Introduction: Alibaba Cloud Message Service (C2DM) launched by Google is the second generation.


Advantages: the services provided by Google are native and simple, and there is no need to implement or deploy the server.


Disadvantage: the Android version is limited (must be later than Version 2.2). This service is not stable enough in China and users need to bind Google accounts, because Google is limited.




6. What should I do if I use the database to store the existing app App2 and the new App1.1? How to save existing data?


SqlLite: onCreateonUpdate () update is used for upgrade. You can perform data and table operations.

In onUpgrade (), how does one adjust the table structure without modifying data?


7. Now we need to implement an alarm software. How should we implement its alarm timing function?


1. Custom: start the service at the backend to verify the current time, get the set time of the alarm clock from the database, and perform time matching,

OK.


2 Android: The AlermManager provided by the system can be operated through related APIs.



8. What is the difference between FrameLayout and RelativeLayout? What scenarios are applicable?


Concept of the FrameLayout layer: all child controls of the worker are stacked.

By default, it is in the upper left corner.


Relative layout of RelativeLayout:

By default, all the sub-spaces are in one layer.

Relative: there is a relative relationship between controls.

By default, it is in the upper left corner.

Applicable scenarios:

FrameLayout: Multiple controls are stacked together. Add a thumbs up button on the top of the sample.

RelativeLayout: it is mainly used for quick control of its controls, for example, a general logon interface.



The relative layout of RelativeLayout is that the positions of the control can be specified relative to who is in the control;

Framelayout frame Layout

That is, the control that is first defined will be followed by the control defined below; FrameLayout is mainly in the layout between multiple layers, and RelativeLayout is the layout between different positions in the same layer.




9. What is the role of Fragment? How to use it?


Purpose:

Reuse of interface content


How:

This Fragment encapsulation can be used when multiple interfaces or multiple parts of one interface are the same in the software.

Currently, Fragment improves code reusability.


Http://blog.csdn.net/yangdeli888/article/details/7842029

Fragment is used to describe some behaviors or some user interfaces. In an Activity, you can combine multiple fragment to create multiple UI panels in a single activity, and reuse fragment in multiple activities. you can think of fragment as a module in an activity. fragment has its own lifecycle, receives its own input events, and you can add or remove it from the running activity.

A fragment must always be embedded in an activity, and the lifecycle of the fragment is affected by the activity.

Fragment exists in the ViewGroup of the Activity.

OnCreate ()
Called when fragment is created, you should initialize some practical components, such as

OnCreateView ()
When the system calls fragment to draw a user interface for the first time, if you draw a UI in your fragment, you must return a View. Of course, you can return null to indicate that this fragment has no UI.





9. What is the Cookie standard in HTTP? What is the function?


Purpose:

Cookie: Session persistence between the client and the server and data transmission (data storage ).


Cookie: the client receives the Http header field Set-Cookie sent by the server to obtain the information transmitted by the server.

When the client sends an Http request, it passes the Cookie info transmitted by the server it stores.


Content format:

Name = value Path =/xxx domain = .Baidu.com




Cookies are a technology that allows the website server to store a small amount of data to the client's hard disk or memory, or to read data from the client's hard disk. Cookies are a very small text file placed on your hard disk by the Web server when you browse a website, it can record your user ID, password, browsed webpage, stay time, and other information. When you come to this website again, the website can read Cookies and learn your related information to make corresponding actions, such as displaying your welcome slogans on the page, or you can log on directly without entering the ID or password. Essentially, it can be viewed as your ID card. However, Cookies cannot be executed as code, nor are viruses transmitted. They are private to you and can only be read by servers that provide them. The saved information fragments are stored in the form of "name/value" pairs (name-value pairs). A "name/value" pair is only a piece of named data. A website can only obtain information stored on your computer. It cannot obtain information from other Cookies, or get anything else on your computer. Most of the content in Cookies is encrypted. Therefore, generally, users only seem to have meaningless combinations of letters and numbers. Only CGI processors on the server can understand their true meanings. Because Cookies are transmitted from websites we browse to text files or data in memory on users' computer hard disks, their locations are closely related to the operating systems and browsers used. In Windows 9X, Cookies are stored in C: WindowsCookies. in Windows NT/2000/XP, Cookies are stored in C: users and Settings user name Cookies. The cookie file on the hard disk can be read by a Web browser. Its command format is: User Name @ website address and number of characters. txt. For example, in my computer, the cookie name is ch@163%1%.txt. Note that Cookies on hard disks are text files rather than programs. In particular, there is another file similar to the cookie, that is, the session, which has almost the same role as the cookie. The biggest difference is that the session is placed on the server side, the cookie is on the client. All users who know the cookie should know the session. You can search for the session content online.




10. How to handle the 302,307,304 status code returned by the server?


302 307: Redirection:


302: the address of the temporary (redirection) network request jumps. You need to obtain the Location field of the Http header for reconnection.

307: Reconnect the Loaction field as above.


304: Not Modified

This is mainly for network data caching. The server defines an ID for each resource.

And the time mark of the last modification. The client saves these fields in the cache. When the client sends a request,

The client sends information. The server checks whether the information is changed. The Server Returns Error 304.

100 Continue

The initial request has been accepted, and the customer should continue to send the rest of the request

101 Switching Protocols

The server converts a client-compliant request to another protocol.

200 OK

Everything is normal. The response documents for GET and POST requests follow

201 Created

The server has created a document and the Location header provides its URL.

202 Accepted

The request has been accepted, but the processing has not been completed.

203 Non-Authoritative Information

The document has been returned normally, but some response headers may be incorrect because the copy of the document is used.

204 No Content

If no new document exists, the browser should continue to display the original document. This status code is useful if the user regularly refreshes the page and the Servlet can determine that the user document is new enough.

205 Reset Content

There is no new content, but the browser should reset the content it shows. Used to force the browser to clear the input content of the form

206 Partial Content

The client sends a GET request with a Range header, and the server completes the request.

300 Multiple Choices

Documents requested by the customer can be found in multiple locations, which are listed in the returned documents. If the server needs to give priority, it should be specified in the Location response header.

301 Moved Permanently

The document requested by the customer is elsewhere. The new URL is provided in the Location header, and the browser should automatically access the new URL.

302 Found

Similar to 301, but the new URL should be treated as a temporary alternative, rather than permanent.

303 See Other

Similar to 301/302, the difference is that if the original request is POST, the redirection target document specified by the Location header should be extracted through GET

304 Not Modified

The client has a buffered document and sends a conditional request (generally, the If-Modified-Since header is provided to indicate that the customer only wants to update the document on a specified date ). The server tells the customer that the original buffer documentation can still be used.

305 Use Proxy

The document requested by the customer should be extracted from the proxy server specified by the Location header

307 Temporary Redirect

It is the same as 302 (Found. Many browsers mistakenly respond to the 302 response for redirection. Even if the original request is POST, it can only be redirected when the POST request actually responds to 303. For this reason, HTTP 1.1 adds 307 to clear the region code in several states: When a 303 response occurs, the browser can follow the redirected GET and POST requests; if a 307 response occurs, the browser can only follow the redirection to get requests.

400 Bad Request

The request has a syntax error.

401 Unauthorized

The customer attempted to access the password-protected page without authorization. The response contains a WWW-Authenticate header. the browser displays the username/password dialog box accordingly, and then sends a request again after entering the appropriate Authorization header.

403 Forbidden

Resource unavailable.

404 Not Found

The specified resource cannot be found.

405 Method Not Allowed

Request methods (GET, POST, HEAD, Delete, PUT, TRACE, etc.) are not applicable to specified resources.

406 Not Acceptable

The specified resource has been found, but its MIME type is incompatible with the one specified by the customer in the Accpet header.

407 Proxy Authentication Required

Similar to 401, the customer must first be authorized by the proxy server.

408 Request Timeout

The customer has not issued any request within the waiting time of the server license. The customer can repeat the same request later.

409 Conflict

It is usually related to PUT requests. The request cannot be successful because the request conflicts with the current status of the resource.

410 Gone

The requested document is no longer available and the server does not know which address to redirect. It differs from 404 in that if 410 is returned, the document permanently leaves the specified position, and 404 indicates that the document is unavailable for unknown reasons.

411 Length Required

The server cannot process the request unless the client sends a Content-Length header.

412 Precondition Failed

Some prerequisites specified in the request header fail.

413 Request Entity Too Large

The size of the target document exceeds the size that the server is willing to process. If the server thinks it can process the request later, it should provide a Retry-After Header

414 Request URI Too Long

URI is too long

416 Requested Range Not Satisfiable

The server cannot meet the Range header specified by the customer in the request.

500 Internal Server Error

The server encountered unexpected circumstances and could not complete the customer's request

501 Not Implemented

The server does not support the functions required to implement the request. For example, the customer sends a PUT request not supported by the server.

502 Bad Gateway

When the server acts as a gateway or proxy, in order to complete the request to access the next server, but the server returns an INVALID RESPONSE

503 Service Unavailable

The server fails to respond due to maintenance or heavy load. For example, Servlet may return 503 when the database connection pool is full. A Retry-After header can be provided when the server returns 503

504 Gateway Timeout

Used by a proxy or gateway server, indicating that the remote server cannot receive a response in a timely manner.

505 HTTP Version Not Supported

The server does not support the HTTP Version specified in the request




11. How do I load images from the network when each Item in ListView contains images?


1 Adaptert GetView ()

2. Check whether the cache exists. If no, enable the thread, asynchronous task, and Volley to download image data.

3. Update UI HandLerMessage AsyncTask () ViewHolder ()



Open a separate queue for downloading list images and call back and refresh the adapter in the activity. The adapter retrieves an image from the local device.



12. What does AsyncTask support for fan parameters?


AsyncTask <传进的参数类型,进度类型,返回数据的类型>


1. Description of three generic parameters of AsyncTask (the three parameters can be of any type)

2. First parameter: parameter type of the doInBackground () method

3. Second parameter: parameter type of the onProgressUpdate () method

4. Third parameter: The parameter type of the onPostExecute () method passed in, which is also the type returned by the doInBackground () method


13. What parts of AsyncTask run on the main thread? How can I update the UI information through AsyncTask?Can I use the code to control the AsyncTask stop??


Main thread:

OnPostExecute ()

onPreExecute(),

onProgressUpdate(Progress...),


Sub-thread:

DoInBackground ()

_______________________________________________________________________________________ S

Can I use the code to control the AsyncTask stop:


Final boolean

Cancel (boolean mayInterruptIfRunning)



Certificate -------------------------------------------------------------------------------------------------------------------------------------------------

The execution of AsyncTask is divided into four steps. Each step corresponds to a callback method. developers need to implement these methods.

* 1) inherit AsyncTask
* 2) implement one or more of the following methods defined in AsyncTask
* OnPreExecute (), which is called by the UI thread before the actual background operations are performed. You can make some preparations in this method, such as displaying a progress bar on the interface or instantiating some controls. This method does not need to be implemented.
* DoInBackground (Params...) will be executed immediately after the onPreExecute method is executed. This method runs in the background thread. Here, we will be mainly responsible for performing the time-consuming background processing. You can call publishProgress to update the real-time task progress. This method is an abstract method and must be implemented by sub-classes.
* OnProgressUpdate (Progress...), after the publishProgress method is called, the UI thread will call this method to display the Progress of the task on the interface, for example, through a Progress bar.
* OnPostExecute (Result): After doInBackground is executed, the onPostExecute method will be called by the UI thread, and the background computing Result will be passed to the UI thread through this method, and displayed to the user on the interface.

* OnCancelled (), called when the user cancels the thread operation. It is called when onCancelled () is called in the main thread.



14. Handler, what is the role of Message? Use Cases?


It is mainly used for communication between threads. The subthread uses Handler to send a message to the main thread for data update.


The sub-thread completes data update and uses Handler + Message to update the UI.


Handler is used mainly because android cannot access the network in the main thread (that is, the UI thread), and cannot access the UI thread elements in the Child thread. Generally, the network is accessed in the Child thread, and then the Handler sends a message to notify the main thread to process the UI update operation.


15. describes how Android supports i18n.

I18n is called internationalization. The software is available in res/vales and other folders with language modifiers. For example: values-zh

Language, style, and size xml resources.

When the Android mobile phone starts the software or displays the layout interface, it matches resources based on the language set by the current mobile phone.

For optimal matching.

For example, if Android is set to Chinese, when android starts the software, resources are loaded at the end of-zh,

Folder. If not, the default Values file is loaded. The adaptability of mobile phones.


Internationalization. Android provides excellent support for i18n and L10n. Android does not have a dedicated API to provide internationalization, but uses the naming of different resources to achieve internationalization,

In addition, this naming method can also be used to differentiate hardware, such as using different images for different new visual screens.


17. What is the difference between final and finally in Java?

Final-modifier (keyword) If a class is declared as final, it means that it cannot generate a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declare variables or methods as final to ensure that they are not changed during use. Variables declared as final must be declared with an initial value, which can only be read and cannot be modified in future references. Methods declared as final can only be used and cannot be overloaded.

Finally-The finally block is provided for troubleshooting. If an exception is thrown, the matched catch clause is executed, and the control enters the finally block (if any ).


17.2. What is the storage principle of Hashtable? Assume that the Book class and the Person class correspond one by one. What should the Book class do if you need to store the Key (Book)-Value (Person) format? What to do with Person.


Java API comprehension:


HashTable HashMap uses the Hash algorithm.

Calculate the HashCode () method of the key object. Calculate a HashCode. Use hashCOde to locate the storage location of objects.

You can store and search by location. When you need to call the put get remove Method, you also need to determine whether the keys are the same. Key object,

Boolean equals (Object o) must be overwritten );

Step: locate the object based on the HashCode and determine whether the object to be located is equal to the passed parameter? To perform operations.


The hashCode () equals () method must be rewritten in the Book.

The Person object cannot be empty. HashTable

Bytes -------------------------------------------------------------------------------------------------------------------------

A hash table can obtain records based on keywords (a typical example is a string key value, because she has established a record storage location internally-that is, a set of mappings between index numbers and keywords in the internal array f, so when searching, you only need to find the number f (K) corresponding to the given key value f Based on the ing relationship, you can directly obtain the target data Hashtable [K] = Hashtable from the array. internalArray [f (K)] without having to traverse and compare the array. this ing relationship f is called a hash function.


18. What are the descriptions and differences between the factory mode and Singleton mode?


Singleton mode: Only one object instance can be created during the entire program running.

It is mainly used for content sharing and data sharing.


Factory mode: Configure according to the passed parameters. Create an instance.





In the factory mode, the most important thing is to meet the polymorphism principle in the object-oriented design. In the application, you only need to create a factory-class interface and then call the production product method of this interface, but the specific implementation does not need to be considered by the application. He only needs to know that the method of the interface he is using must be available!

The Singleton mode is also called the singleton mode. In fact, I think this mode is the simplest, as long as it meets two basic conditions: first, it provides and only provides one global access node, second, ensure that no more than one instance is generated, that is, instance control is required, that is, the constructor must be controlled.

The Singleton mode is based on the simple factory mode, and both of them require the factory method to have special logic in order to realize the reuse of product instances cyclically.



19. What is the difference between the adapter mode and the listener mode?


Adapter: a bridge between data and the UI.

You can use an adapter to convert data to the Ui.


Listener mode: The event processing mode of the UI control provides a design mode for external code to listen to events. Listening all the time. For example


(1) Class adapter:

When the customer defines the expected behavior in the interface, we can apply the adapter mode, provide a class to implement this interface, and extend the existing class, you can create child classes to achieve adaptation.

The following is a UML diagram of the class adapter:

(2) Object Adapter:

The combination of object adapters not only meets the user expectation interface, but also reduces the poor coupling between codes. We recommend "Object adaptation" at work ". The following is a UML diagram of the Object Adapter:

(3) default adapter mode:

The default adapter mode is a special adapter mode, but this adapter is implemented by an abstract class and must implement all the methods specified in the target interface in the abstract class, but the implementation of many methods is "mediocre", that is, these methods are empty methods. The specific subclass must inherit this abstract class.

Listener mode, that is, observer mode. It is sometimes called the publish/subscribe mode. The observer mode defines a one-to-many dependency, allowing multiple observer objects to listen to a topic object at the same time. When the status of this topic object changes, it notifies all observer objects so that they can automatically update themselves.


20. What is the serialization method in Java? How to serialize multiple records of Book [title, author, price? (Two methods are described. All files must be stored in binary format ).


Book implementation: java. io. Serializable must be implemented and then ObjectOutputStream must be used for data serialization to save data.

DataOutputStream stores data. You can customize the data structure.


When serializing an object, the object must implement the java. io. Serializable interface. The Serializable interface does not contain any methods. This can be understood as declaring that the object is a Serializable method. When we serialize an object, we do not want to serialize some attributes (which can reduce the data volume), so we can declare this attribute as an instantaneous state (with the transient keyword ). In addition, static fields are not serialized.






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.