Android Development interview by--6. Common interviewer Questions Android ② (update ... )

Source: Internet
Author: User

 

Copyright NOTICE: This article for the Dream-finddreams original article, please pay attention to: Http://blog.csdn.net/finddreams

Follow Finddreams Blog: http://blog.csdn.net/finddreams/article/details/44560061
1.HttpURLConnection and httpclient What are their strengths and weaknesses?
HttpURLConnection in the previous version of the 2.3 is a bug, so the previous version recommended the use of HttpClient, but Google has now not maintained HttpClient, 5.1 inside has the HttpClient label expired. In addition httpurlconnection support gzip compression, etc., recommend it preferred.
Before Froyo (2.2), HttpURLConnection had a major Bug, calling the close () function would affect the connection pool, causing the connection reuse to fail, so keepAlive was required to use httpurlconnection before Froyo.
In addition, gzip compression is enabled by default on Gingerbread (2.3) httpurlconnection, which improves the performance of HTTPS, and Ice Cream Sandwich (4.0) HttpURLConnection supports the request result cache.
Plus httpurlconnection itself API is relatively simple, so for Android, after 2.3 recommended to use HttpURLConnection, previously recommended to use Androidhttpclient.

The comparison of XML parsing methods in 2.Android development, and its advantages and disadvantages?
Dom,sax,pull parsing.
The advantage of SAX parser is that the parsing speed is fast and the memory consumption is low.

The DOM is stored in memory in a tree structure, so retrieval and update efficiency is higher. However, for very large documents, parsing and loading the entire document will be very resource-intensive, not suitable for mobile;

The pull parser operates in a similar way to sax, and is an event-based pattern, and the pull parser is compact, fast, and easy to use, making it ideal for Android mobile devices, and the pull parser is used internally by the Android system to parse various XML.

3. How do you do multi-resolution adaptation in the development process?
1. Create different layout files based on different resolutions
2. Create a picture of different resolution resources according to different resolution
3. When the program starts, get the current screen resolution and density, in the code to adapt
4. Write different dimen files for different resolutions.
5. In fact, there is more use of fragement

4. How do you solve a bug at work?
1. Look at log logs
2.Log can not solve the breakpoint debugging
3. If debug is not possible
4. Just around the exception code LOG.E ("Error", "1"), 2,3,4,5,6,7,8,9 every other row a log output, see the results
5. Find the problem and find your own ideas. If it's a technical bottleneck, Google's

5. Why is it recommended to use the static keyword when declaring Viewholder internal classes?
In fact, this is one of the main differences between static inner class and non-static inner class. A non-static inner class implicitly holds a reference to an external class, just as it is common to have custom adapter in the activity class, and then inside the adapter class, you can invoke the external activity method arbitrarily. When you define an inner class as static, you cannot invoke an instance method of an external class because the static inner class does not hold a reference to the outer class. Declares Viewholder static inner classes, which can be referenced by Viewholder and external classes. Everyone will say that the general Viewholder are very simple, not defined as static is also OK. That's true, but if you define it as static, you know what it means. In case one day you add some complex logic to this viewholder and do some time-consuming work, then if Viewholder is a non-static inner class, memory leaks are easy. If it is static, you cannot refer to external classes directly, forcing you to focus on how to avoid referencing each other. So it is a good habit to define the Viewholder inner class as static.
A non-static inner class implicitly holds a strong reference to an external class, which can only lead to memory leaks, and in general the use of Viewhodler does not lead to memory leaks, plus static is a good habit

6. How to display an ultra-high-definition picture or a long image under the condition of non-distortion?
1, by calculating the Bitmapfactory.options object's insamlesize value and so on compression picture.
2, use WebView to load the picture;
3, using Mapview or Tileview to display pictures (similar to the map of the mechanism);

7. What are the methods for timing and delay tasks in Android? What are their application scenarios?
Countdown class
With Countdowntimer

Delay class
Countdowntimer, Countdowninterval can be cleverly set to the same as millisinfuture, so it will only call once Ontick and once OnFinish
Handler.sendmessagedelayed, can refer to the internal implementation of Countdowntimer, simplified, personal comparison recommended this
TimerTask, the code is a bit confusing.
Thread.Sleep, it feels bad.
Using the handler method Postdelay (runnable, Delaytime)

Timing class
If you refer to deferred classes, calculate how much time you want to delay.
Handler.sendmessageattime
Alarmmanager, suitable for long-term time, such as alarm

8. Talk about your knowledge of strongreference, WeakReference and SoftReference.
Strong reference (Strongreference): A reference to a class that is common in code, like object obj = new Object (), as long as a strong reference exists, the GC never reclaims the referenced object.
Soft Reference (SoftReference): Used to describe some objects that are also useful but not necessary. For objects associated with soft references, these objects are included in the recovery scope for a second collection when the system is about to have a memory overflow exception. If this collection does not have enough memory, a memory overflow exception will be thrown. After JDK 1.2, the SoftReference class was provided to practice soft references.

Weak references (WeakReference): Also used to describe non-essential objects, but its strength is weaker than soft references, and the object associated with a weak reference only survives until the next GC occurs. When the GC is working, the objects associated with the weak reference are reclaimed regardless of whether the memory is sufficient at the time. After JDK 1.2, the WeakReference class was provided to implement weak references.

Virtual Reference (phantomreference): This reference is not mentioned by Po master, but it can also be understood in passing. A virtual reference, also called a phantom reference or phantom Reference, is the weakest reference relationship. Whether an object has a virtual reference exists, does not affect its lifetime at all, and cannot obtain an object instance through a virtual reference. The sole purpose of setting a virtual reference for an object is to receive a system notification when the object is recycled by GC. The Phantomreference class is provided after JDK 1.2 to implement a virtual reference.

9. How is the network layer in your application designed?
1. Android-async-http.
Encapsulated the next common method, get post upload download, all requests I am using the synchronization request.
The specific usage is usually with the business logic, and my business logic is handled asynchronously.
I dealt with the cache of the result of the network request separately. It is not placed on the network layer.

2. Encapsulation based on HttpURLConnection, including package of request success, failure, request, network problem and so on, using broadcast to interact with UI
3. Direct use of open source third-party frameworks such as Xutils,afinal,okhttp,volley;

Bitmap is a class that is used frequently in Android, and it represents a picture resource.
Bitmap consumes a lot of memory, and if you don't pay attention to optimizing your code, you often get an oom problem, which is typically optimized in such a way:
1. Use the cache;
2. Compress the picture;
3. timely recovery;

10. Talk about your understanding of bitmap, when should you manually call Bitmap.recycle ()?
As to when to call recycle manually, this depends on the scenario, the principle is that when we no longer use Bitmao, we need to recycle it. In addition, we need to note that before 2.3 the bitmap object and the pixel data is stored separately, the bitmap object exists in the Java heap and the pixel data is stored in the native memory, it is necessary to call recycle reclaim memory. However, after 2.3, both the bitmap object and the pixel data are present in the heap, and the GC can reclaim its memory.

11.ViewPager Load fragment optimization problem? How to do that when switching the interface time-lapse load?
Using the Setuservisiblehint method in fragment can be done.

private boolean hasloadedonce = FALSE; //your boolean field @Override public void setUserVisibleHint ( Span class= "Hljs-keyword" >boolean isvisibletouser) {super.setuservisiblehint ( Isvisibletouser); if (this.isvisible ()) {//we Check the fragment is becoming visible if (isvisibletouser &&!hasloadedonce) {//do Something}}}          
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

12 What is AAR? What is the difference between AAR and jar?
The "AAR" package is a binary release package for the Android Class Library project.

The file extension is. aar,maven The project type should also be AAR, but the file itself is a zip file with the following items:

/androidmanifest.xml (mandatory)
/classes.jar (mandatory)
/res/(mandatory)
/r.txt (mandatory)
/assets/(optional)
/libs/*.jar (optional)
/jni//*.so (optional)
/proguard.txt (optional)
/lint.jar (optional)
These entries are located directly in the root directory of the zip file.
Where the R.txt file is the output of the AAPT with parameter –output-text-symbols.

Jar packaging cannot contain resource files, such as some drawable files, XML resource files, and so on, AAR can.

13. How do I encrypt URLs to prevent it from being hacked?
Encryption into JNI is still captured by the grab tool. The last way is to do the HTTPS certificate two-way encryption authentication

the difference between 14.Android fragment and activity
You can understand that fragment is a special view that is responsible for the presentation of a module or a special part.
Most fragment are based on activity and are managed by the activity's Fragmentmanager.
Fragment can solve the problem of multi-activity, will be 3.0 before the frequent activity jump to an activity within the fragment switch.
Fragment can solve the problem of fragmentation.
Fragment is a new android3.0.
Fragment can be reused
Fragment must be nested within the activity and its life cycle is affected by activity.

15.Service and broadcast broadcastreceivre will there be ANR?
Service, the broadcast will appear ANR
Service, broadcast is the main thread, since it is the main thread of course will be ANR so time-consuming operation or must be another thread
Popular say time-out: Activity 5 seconds, broadcast 10 seconds, Server 20 seconds

16. What design patterns do you use in your usual development, and can you talk about the usage scenarios of these design patterns?
In peacetime, there are more singleton patterns (used when only one object is instantiated in memory), adapter mode (typically the adapter of the ListView and GridView), builder mode (ALERTDIALOG.BUILDER), the observer pattern may be more subtle, In the Android source code baseadapater the implementation of the notifydatasetchanged (? )
Single Example: Downloadmanager

Top
8
Step
0
      • Previous Android development interview by--5. Common interviewer questions Android question ①
      • The next Android circular scrolling banner of the perfect implementation, packaging convenient, smooth transition, load images from the network, click on the ad to enter the corresponding URL

Android Development interview by--6. Common interviewer Questions Android ② (update ... )

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.