A summary of questions that are often asked in Android interviews
Source: Internet
Author: User
<span id="Label3"></p><p><p>1, The main use of Android in several design patterns:</p></p><p><p>(1) template mode</p></p><p><p>such as activity, each time you create a new activity will overwrite OnCreate (), onStart () method, etc., These methods in the parent class is equivalent to a Template.</p></p><p><p>(2) Viewer Mode</p></p><p><p>Listener equivalent to an observer, the response to some events are input observation, when found to respond to the corresponding Treatment.</p></p><p><p>(3) Singleton mode (purpose: you want an object to create only one instance and provide a global access point.) )</p></p><p><p>Application</p></p><p><p>(4) Adapter Mode (equivalent to Real-life Plug)</p></p><p><p>baseadapter, Simpleadapter</p></p><p><p>(5) Factory mode (create Bitmap)</p></p><p><p>Bitmapfactory.decoderesource (); Bitmapfactory is equivalent to a bitmap factory.</p></p><p><p>(6) Proxy Mode</p></p><p><p>Using Aidl to define a remote service in an Android system requires proxy Mode.</p></p><p><p></p></p><p><p>2, Android's Four components</p></p><p><p>Activity, Service, broadcast Receiver, content provider</p></p><p><p></p></p><p><p>3. Steps for customizing controls</p></p><p><p>(1) define a class to inherit from the system view;</p></p><p><p>(2) Configure the layout file in xml;</p></p><p><p>(3) rewriting some methods of the parent class, such as onmeasure, onDraw, onlayout, etc.;</p></p><p><p>(4) Application of Custom view in the program;</p></p><p><p></p></p><p><p>4. The role of onmeasure, OnDraw and OnLayout</p></p><p><p>Onmeasure () is used to set the size of the view, which is the width and height of the view;</p></p><p><p>OnLayout (), The layout action is used to set where the view appears on the Screen. OnLayout (), in view, This function does nothing, for the ViewGroup type layout sub-view;</p></p><p><p>OnDraw (), The draw operation uses the parameters obtained from the previous two sections to display the view on the Screen.</p></p><p><p>(1) drawing the background;</p></p><p><p>(2) Draw the View itself, call the OnDraw () method;</p></p><p><p>(3) draw a sub-view, Dispatchdraw () container class will use this method;</p></p><p><p>(4) Draw the scroll bar.</p></p><p><p></p></p><p><p>5. Life cycle of activity</p></p><p><p>(1) start activity: The system calls the OnCreate method first, then calls the OnStart method, and finally calls Onresume,activity into the running State.</p></p><p><p>(2) the activity is currently covered by other activity or locked: the system calls the OnPause method, pausing the execution of the current Activity.</p></p><p><p>(3) the current activity from the covered state back to the foreground or unlock screen: the system will call the Onresume method, again into the running State.</p></p><p><p>(4) the current activity to go to the new activity interface or press the home button back to the main screen, self-retired: the system will first call the OnPause method, and then call the OnStop method, into a stagnant state.</p></p><p><p>(5) the user backs back to this activity: the system calls the Onrestart method first, then calls the OnStart method, and finally calls the Onresume method, again into the running State.</p></p><p><p>(6) the current activity is in a covered state or the background is not visible, that is, the 2nd and 4th steps, The system memory is not enough, kill the current activity, and then the user returned to the current Activity: call OnCreate method again, OnStart method, Onresume method, Enter the running State.</p></p><p><p>(7) the user exits the current activity: the system calls the OnPause method first, then calls the OnStop method, and finally calls the Ondestory method to end the current Activity.</p></p><p><p></p></p><p><p>6. Principle of handler mechanism</p></p><p><p>Sending messages and processing messages</p></p><p><p></p></p><p><p>7. GC Memory leaks</p></p><p><p><span style="line-height: 26px; font-family: Arial; font-size: 14px;">The situation Arises:<br>(1) the cursor of the database is not closed<br>(2) when constructing adapter, the cache is not used Contentview<br>The optimization problem of the derived listview-----reduce the object that creates the view, use Contentview fully, and use a static class to optimize the process of processing getview/<br>(3) use recycle () to free memory when bitmap objects are not used<br>(4) the life cycle of objects in activity is greater than activity<br>Debug Method: ddms==> heapszie==>dataobject==>[total Size]</span></p></p><p><p></p></p><p><p>8, What is the ANR how to avoid it</p></p><p><p>Anr:application Not responding, five sec</p></p><p style="margin: 0px; padding: 0px;"><p style="margin: 0px; padding: 0px;">In android, the two system services, Activity Manager and window manager, are responsible for monitoring the response of the Application. Android Displays the ANR dialog box when the following conditions Occur:</p></p><p style="margin: 0px; padding: 0px;"><p style="margin: 0px; padding: 0px;">More than 5 seconds of response to input events such as keystrokes, Touch-screen events</p></p><p style="margin: 0px; padding: 0px;"><p style="margin: 0px; padding: 0px;">Intent receiver (intentreceiver) has not been executed for more than 10 seconds</p></p><p style="margin: 0px; padding: 0px;"><p style="margin: 0px; padding: 0px;">The Android application runs completely in a separate line approached (for example, main). This means that any operation that runs in the main thread and consumes a lot of time will cause the Anr. Because at this point, your application has no chance to respond to input events and intent broadcasts (Intent broadcast).</p></p><p><p><span style="font-family: Arial;"><span style="line-height: 26px; font-size: 14px;">therefore, any method that runs in the main thread should do as little work as Possible. In particular, important methods in the life cycle of the activity, such as OnCreate () and Onresume (), should be more So. Potentially more time-consuming operations, such as accessing networks and databases, or expensive computations, such as changing the size of bitmaps, need to be done in a separate sub-thread (or with an asynchronous request, such as a database operation). But this does not mean that your main thread needs to go into a blocking state that has waited for the child thread to End--and does not need to call the therad.wait () or Thread.Sleep () method. instead, The main thread provides a handle (Handler) for the child thread, allowing the child thread to call it at the end of the process (xing: see the example of snake, which differs from what we were in contact with previously). Using this approach involves your application, which ensures that your program responds well to the input and avoids the ANR resulting from an input event that is not processed for more than 5 seconds. This practice needs to be applied to all threads that display the user interface, because they all face the same timeout problem.</span></span></p></p><p><p></p></p><p><p><span style="font-family: Arial;"><span style="line-height: 26px; font-size: 14px;">9,<span style="font-family: 宋体; -ms-word-wrap: break-word;">How to optimize the ListView (this is very important, many times asked)<br style="-ms-word-wrap: break-word;"><span style="-ms-word-wrap: break-word;">(1) Paging Load<br style="-ms-word-wrap: break-word;"><span style="-ms-word-wrap: break-word;">(2) Convertview Cache<br style="-ms-word-wrap: break-word;"><span style="-ms-word-wrap: break-word;">(3) Viewholder<br style="-ms-word-wrap: break-word;"><span style="-ms-word-wrap: break-word;">(4) scrolllistener, Remember the state of the slide</span></span></span></span></span></span></span></p></p><p><p></p></p><p><p>10, activity of the four types of startup mode</p></p><p><p>(1) Standard</p></p><p><p>Mode startup mode, activity is created each time the activity is activated and placed in the task Stack.</p></p><p><p>(2) Singletop</p></p><p><p>If there is an instance of the activity at the top of the task, reusing the instance will create a new instance and put it in the top of the stack (even if the activity instance already exists on the stack, as long as it is not on top of the stack, an instance will be created).</p></p><p><p>(3) Singletask</p></p><p><p>If an instance of the activity is already in the stack, the instance is reused (onnewintent () of the instance is invoked). When reused, the instance is returned to the top of the stack, so the instances above it will be removed from the STACK. If the instance does not exist in the stack, a new instance is created to be put into the STACK.</p></p><p><p>(4) singleinstance</p></p><p><p>Create the activity instance in a new stack and have multiple apps share the activity instance in the Stack. Once an instance of the activity in the schema is present on a stack, any application that activates the activity will reuse the instance in that stack, with the effect of sharing an app with multiple applications, regardless of who activates the activity into the same application.</p></p><p><p>A summary of questions that are often asked in Android interviews</p></p></span>
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