The following questions are encountered by the poster during the interview with the Android communication group. If you have good questions or good insights, please share them. The poster will maintain this post for a long time.
Advanced interview questions for a company (2015-03-14) [Thanks to helder for sharing]
1. Detailed description of the Android system architecture, including calling between layers, binder, jni, and reading and writing methods of underlying files
2. Describe one of your own projects, and ask to draw a structural diagram, UML diagram, and describe the technical points, technical difficulties and solutions of the project in detail.
3. An algorithm
4. Talk about your own project management methods and understanding of agile software development
Basic Interview Questions (2014-04-18)
1. Please explain the relationship between Message, Handler, Message Queue, and Looper in the single-threaded model.
Take the main thread as an example. When the main thread starts, it will call the() method, initialize a Looper, put it in Threadlocal, and then call() to continuously traverse the Message Queue.
The creation of a Handler depends on the Looper in the current thread. If the current thread does not have a Looper, it must call(). Handler, sendMessage to MessageQueue, Looper keeps
Get the message from the MessageQueue and call back the handleMessage method.
2. If there is a 100M file that needs to be uploaded to the server, and the server form can only be uploaded by 2M at most. What method can be used?
This question is not very clear. I think, first of all, uploading data using the http protocol, especially under Android, has nothing to do with form. Traditionally, writing files in form is written and uploaded, which is actually done by the browser.
It is to parse our data into strings and send it to the server in a stream. The uploaded files are POST, which has no restrictions on size.
Back to the topic, it can be said that if we can only upload 2M each time, then we may only truncate the files and upload them separately.
3. What is the difference between memory overflow and memory leak? When will a memory leak occur? What are the methods of memory optimization?
Memory overflow is commonly understood as the memory required by the software (application) to run, exceeding the maximum memory it can be used for.
Memory leak is our use of a certain memory space, which is not released after use.
Memory optimization: The part in Android that is prone to memory overflow is the loading of images. We can use image compression and the purpose of using LruCache cache to control the memory that images can use.
There is also timely shutdown of more resource-consuming objects, such as Database Conn, various sensors, Service, etc.
4. In which scenarios is AsyncTask used? What are its flaws? How to solve it?
The scenario used by AsyncTask is that we need to perform some time-consuming operations, update the main thread after the time-consuming operation is completed, or update the main thread's UI during the operation.
Flaw: AsyncTask maintains a thread pool of 128 in length, and can execute 5 worker threads and a buffer queue. When there are 128 threads in the thread pool and the buffer queue is full, if
Submit a task to the thread at this time, a RejectedExecutionException will be thrown.
Solution: A control thread handles the call of AsyncTask to determine whether the thread pool is full. If it is full, the thread sleeps. Otherwise, AsyncTask will be requested to continue processing.
5. Activity uses SharedPreferences to save data. Is there any size limitation?
I really can't find this. . .
6. Is there any limit on the size of data passing through Intent between activities?
It seems to be 40K.
7. Is there any limit on the size of the file when placing files in the assest folder?
The assets directory is more like an appendix type directory. Android does not generate IDs for files in this directory and save them in R class, so it is less compatible with some classes and methods in Android.
At the same time, since you need a string path to get the file descriptors in this directory, the access speed will be slower. However, putting some files in this directory will make some operations more convenient.
For example, copy a database file into system memory. It should be noted that you cannot reference files in the assets directory in Android XML files, and can only be accessed through AssetManager
These files. It is more appropriate to place database files and game data in this directory. In addition, the information about assets and raw online is the same, so the single file of these two
The error** description of the size cannot exceed 1M is also propagating, that is, if a file with a size exceeding 1M is read, it will report "Data exceeds UNCOMPRESS_DATA_MAX (1314625 vs 1048576)"
IOException also extends various solutions. I personally think there should be no such restrictions. In order to verify this statement, I wrote a demo and found that nearly 5M compressed packages are in assets and raw.
All can be accessed normally, so I will correct it here. In theory, as long as the package does not exceed the size limit of Android APK 50M, there is no problem. Of course, it is not ruled out that it was very early Android
Because of the device hardware, aapt restricted the size of these two folders when compiling. If so, this should not happen to the newer version of ADT.
From: /futurexiong/archive/
8. Start a program and you can click the icon on the main interface to enter, or you can jump from a program. What is the difference between the two?
Because I started the program (the main interface is also an app), I found that there is an activity set to <category android:name="" /> in this program,
So this launcher will put the icon on the main interface. When the user clicks on the icon, an Intent is issued:
Intent intent = ().getLaunchIntentForPackage(packageName);
(intent);
If you jump over, you can jump to any allowed page. If a program can be downloaded, then the page you actually download may not be the home page (or may be the home page). At this time, you should still construct an Intent, startActivity.
There may be multiple views in this intent, and download is possible. The system will select programs or pages that can be opened for your Intent based on the function of registering with the system by third-party programs. So the only thing
The difference is that the intent action launched from the icon click is relatively single, and the jump or startup may have more styles. Essentially the same.
9. Understanding of affinity between programs.
1. By default, all activities of an application have the same affinity and are inherited from the application. The affinity of the application is the package name of the manifest by default.
2. Affinity is like an ID card for Activity, which can tell Task that you are one of them.
3. Application occasions:
a: Re-select the appropriate host Task for Activity according to affinity;
b: Cooperate with the allowTaskReparenting property;
c: Start Activity sets the FLAG_ACTIVITY_NEW_TASK flag using Intent.
10. Can different activities be placed in different Task task stacks for the same program?
Can be placed in different tasks. Different affinity attributes need to be set for different activities. The Intent to start the activity needs to include the FLAG_ACTIVITY_NEW_TASK tag.
11. The life cycle of the Activity when switching horizontal and vertical screens.
1. When the activity's android:configChanges are not set, the screen-cutting will call each life cycle again. It will be executed once when cutting horizontal screen, and it will be executed twice when cutting vertical screen.
2. When setting the activity's android:configChanges="orientation", the screen-cutting will still call each life cycle again, and the horizontal and vertical screens will only be executed once.
3. When setting the activity's android:configChanges="orientation|keyboardHidden", the screen-slicing will not re-call each life cycle, and will only execute the onConfigurationChanged method.
12. What is the full name of AIDL? How does it work?
Full name is: Android Interface Define Language
In Android, each application can have its own process. When writing UI applications, Service is often used. How to pass objects in different processes? Obviously, cross-process memory sharing is not allowed in Java.
Therefore, passing objects can only be split into simple forms that the operating system can understand to achieve the purpose of cross-border object access. In J2EE, using RMI, objects can be passed through serialization. In Android,
Using AIDL method. In theory, AIDL can pass Bundles, but in fact it is more troublesome.
AIDL (AndRoid interface description language) is an excuse description language; the compiler can generate a piece of code through the aidl file to achieve the purpose of communicating internal processes between the two processes through a predefined interface. If necessary
In an activity, to access an object in another service, you need to convert the object into parameters that AIDL recognizes (maybe multiple parameters), and then use AIDL to pass these parameters, at the receiving end of the message,
These parameters assemble the object you need. The mechanism of AIDL's IPC is similar to COM or CORBA. It is interface-based, but it is lightweight. It uses proxy classes to pass values between the client and implementation layers. If you want to use AIDL,
2 things need to be completed: 1. Introduce relevant classes of AIDL. 2. Call the class generated by aidl.
How to create AIDL:
The AIDL syntax is simple and can be used to declare an interface with one or more methods, or to pass parameters and return values. Due to the need for remote calls, these parameters and return values are not of any type.
Here are some data types supported by AIDL:
1. Simple Java programming language types (int, boolean, etc.) that do not require import declarations
2. String, CharSequence does not require special declarations
3. List, Map and Parcelables types, the data members contained in these types can only be simple data types, String and other supported types.
(Also: I didn't try Parcelables, compiled under Eclipse+ADT, but maybe there will be some support in the future
13. Whether the process of dvm and Linux, the process of application is the same concept
The process of Dvm is a dalivk virtual machine process. Each android program runs in its own process. Each android program system will assign it a separate liunx uid (user id).
Each dvm is a process in Linux. So these two processes are a process.
Please indicate the source when reprinting: /lmj623565791/article/details/24015867