Android interview Summary

Source: Internet
Author: User

 

The following questions are all encountered by the landlord during interviews in the android exchange group. If you have good questions or good opinions, please share them. The author will maintain this post for a long time.

 

1. Explain the relationships among Message, Handler, Message Queue, and logoff in the single-thread model.

Take the main thread for example, when the main thread starts, it will call the logoff. prepare () method, initialize a logoff, put it into Threadlocal, and then call logoff. loop () to continuously traverse the Message Queue,

Handler's creation dependency and logoff in the current thread. If the current thread does not have logoff, you must call logoff. prepare (). Handler, sendMessage to MessageQueue, Logoff

Retrieve the message from MessageQueue and call back the handleMessage method.

 

2. If there is a M file, you need to upload it to the server, and the server form can only upload 2 M at most. What method can be used.

This problem is not very clear. I think it is okay to use http to upload data, especially in android. In traditional web, writing and uploading files in form is actually done by browsers.

The data is parsed into strings and sent to the server as a stream. The uploaded files are all in the POST mode. The POST mode has no limit on the size.

Back to the question, we can say that we can only upload 2 MB at a time, then we can only cut off the file and then upload it separately.

 

3. What is the difference between memory overflow and Memory leakage? When Will Memory leakage occur? What are the memory optimization methods?

Memory overflow generally refers to the memory required for running software (applications), which exceeds the maximum available memory.

Memory leakage refers to the use of a certain memory space, which is not released after use.

Memory Optimization: memory overflow in Android is easily caused by image loading. We can use image compression and LruCache cache to control the memory available for images.

In addition, you can close resource-consuming objects in a timely manner, such as Database Conn, various sensors, and services.

 

4. In what scenarios is AsyncTask used? What are its defects? How can this problem be solved?

The Application Scenario of AsyncTask is that we need to perform some time-consuming operations, update the main thread after time-consuming operations are completed, or update the UI of the main thread during the operation.

Defect: AsyncTask maintains a thread pool with a length of 128 and can execute five working threads. There is also a Buffer Queue. When there are already 128 threads in the thread pool and the Buffer Queue is full, if

When a task is submitted to the thread, a RejectedExecutionException is thrown.

Solution: A control thread is used to process AsyncTask calls and determine whether the thread pool is full. If the thread pool is full, the thread will sleep or request AsyncTask to continue processing.

 

5. Is there a limit on the size of data stored by Activity with SharedPreferences?

This cannot be found...

 

6. Is there a limit on the size of data transmitted between activities through Intent?

It seems to be 40 K.

 

7. Are there any restrictions on the size of files in the assest folder? 22

The assets Directory is more like an appendix directory. Android does not generate an ID for the files in this directory and save it in the R class. Therefore, it is less compatible with some classes and methods in Android.

At the same time, because you need a string path to obtain the file descriptor in this directory, the access speed will be slower. However, storing some files in this directory makes some operations more convenient,

For example, copy a database file to the system memory. Note that you cannot reference files under the assets directory in the Android XML file, and can only access the files through AssetManager.

These files. It is appropriate to store database files and game data in this directory. In addition, the information about assets and raw on the Internet is the same.

The ** error ** description cannot exceed 1 MB. That is, if a file larger than 1 MB is read, the following error occurs: Data exceeds UNCOMPRESS_DATA_MAX (1314625 vs 1048576 ).

IOException also provides various solutions. I personally think there should be no such restriction. I wrote a Demo to verify this statement and found that the compressed package of nearly 5 MB is in assets and raw.

Can be accessed normally, so here we can correct it. Theoretically, as long as the package size does not exceed the Android APK 50 m size limit, there is no problem. Of course, it is not ruled out that Android was very early

Aapt restricts the size of these two folders during compilation due to hardware reasons. If so, the new version of the ADT will not.

From: http://my.eoe.cn/futurexiong/archive/5350.html

 

8. Start a program. You can click the icon on the main interface to enter the program. You can also jump from the program. What is the difference between the two?

The reason is that the Startup Program (the main interface is also an app) finds that there is Activity,

Therefore, this launcher will put the icon on the main interface. When a user clicks an icon, an Intent is sent:

Intent intent = mActivity. getPackageManager (). getLaunchIntentForPackage (packageName );

MActivity. startActivity (intent );

If a program can be downloaded, the downloaded page may not be the homepage (or the homepage). In this case, an Intent and startActivity are constructed.

The actions in this intent may have multiple views, and the download may be all. Based on the functions registered with the system by a third-party program, the system selects programs or pages that can be opened for your Intent. So the only one

The difference is that the intent action started from the icon click is relatively single, and the jump or start style from the program may be more. The essence is the same.

 

9. Understanding of the affinity between programs.

1. By default, all the activities of the next application have the same affinity and are inherited from the application. The affinity of the application is the package name of manifest by default.

2. affinity is like an ID card for an Activity. You can tell the Task that you belong.

3. Application scenarios:

A: select a proper host Task for the Activity based on affinity;

B: works with the allowTaskReparenting attribute;

C: Use Intent to set the FLAG_ACTIVITY_NEW_TASK tag to start the Activity.

 

10. Can different activities of the same program be stored in different Task stacks?

It can be placed in different tasks. You need to set different affinity attributes for different activities. The Intent that starts the activity must contain the FLAG_ACTIVITY_NEW_TASK tag.

 

11. lifecycle of the Activity during screen switching.

1. When the android: configChanges of the Activity is not set, the life cycle of the screen is re-called, the screen is executed once, and the screen is split twice.

2. When setting the Activity's android: configChanges = orientation, the screen will be switched to call each lifecycle, and the screen will be executed only once

3. When setting the Activity's android: configChanges = orientation | keyboardHidden, the live cycle is not re-called and only the onConfigurationChanged method is executed.

 

12. What is the full name of AIDL? How to work?

 

Full name: Android Interface Define Language

In Android, each application can have its own process. When writing a UI application, services are often used. In different processes, how can we transmit objects? Obviously, cross-Process Memory sharing is not allowed in Java.

Therefore, objects can only be divided into simple forms that the operating system can understand to achieve cross-border object access. in J2EE, RMI can be used to pass objects through serialization. in Android

The AIDL method is used. In theory, AIDL can transmit Bundle, but in fact it is quite troublesome.

AIDL (AndRoid Interface Description Language) is an excuse to describe the language. the compiler can generate a piece of code through the aidl file and use a pre-defined interface to implement internal communication between two processes.

To access an object in another Service in an Activity, you must first convert the object to a parameter that can be recognized by AIDL (multiple parameters may be involved), and then use AIDL to pass these parameters, use

These parameters are assembled into the desired object. The IPC Mechanism of AIDL is similar to that of COM or CORBA and is based on interfaces, but it is lightweight. It uses the proxy class to pass values between the client and the Implementation Layer. If you want to use AIDL,

Two things need to be done: 1. Introduce the relevant classes of AIDL; 2. Call the class generated by aidl.

AIDL creation method:

The AIDL syntax is very simple. It can be used to declare an interface with one or more methods, or to pass parameters and return values. These parameters and return values are not of any type due to remote calls.

The following are data types supported by AIDL:

1. Simple Java programming language types (int, boolean, etc.) that do not need to be declared by import)

2. Special declarations are not required for String and CharSequence.

3. List, Map, and Parcelables types. The data members of these types can only be simple data types, and Other types supported by the String type.

(In addition, I did not try Parcelables. It cannot be compiled in Eclipse + ADT, and may be supported in the future .)

 

 

13. Check whether the process of dvm is the same concept as that of Linux.

The Dvm process is a dalivk Virtual Machine Process. Each android program runs in its own process, and each android program system assigns a separate liunx uid (user id) to it ),
Each dvm is a process in linux. Therefore, these two processes are one process.

 

 

Paste the question first, and then start to find a way to collect answers ~ Welcome to message ~

 

 

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.