Android interview questions (Classic)

Source: Internet
Author: User

This article is reproduced. I hope my friend has a good interview question to study ......
1. Check whether the process of Android dvm is the same concept as that of Linux.
DVM refers to the Virtual Machine of dalivk. Every Android application runs in its own process and has an independent Dalvik Virtual Machine instance. Every DVM is a process in Linux, so it can be considered the same concept.

2. What is the role of the SIM card EF file?
Sim card file systems have their own specifications, mainly to communicate with mobile phones, sim itself can have its own operating system, EF is used for storage and communication with mobile phones

3. What are the features of Memory Management in the embedded operating system?
Webpage, segment, and segment pages, using MMU, virtual space, and other technologies

4. What is an embedded real-time operating system? Does the Android operating system belong to a real-time operating system?
An embedded real-time operating system can accept and process external events or data at a high speed, the processing result can control the production process or quickly respond to the processing system within the specified time, and control all real-time tasks to coordinate and operate in an embedded operating system. It is mainly used for industrial control, military equipment, aerospace and other fields with demanding system response time requirements, which requires the use of real-time systems. It can be divided into soft real-time and hard real-time. android is based on the Linux kernel, so it is soft real-time.

5. How many bytes does the longest Short Message count?
70 Chinese characters (including punctuation marks), 160 English bytes

6. What are the features and differences of animations in android?
Two types: Tween animation and Frame animation. Tween animation, which allows view components to move, zoom in, zoom out, and change transparency. Another Frame Animation, the traditional animation method, it is achieved through sequential playback of arranged images, similar to movies.

7. handler mechanism Principle
Andriod provides Handler and logoff to satisfy inter-thread communication. Handler first-in-first-out principle. The logoff class is used to manage Message Exchange between objects in a specific thread ).
1) loue: A thread can generate a loue object to manage the Message Queue (Message Queue) in this thread ).
2) Handler: You can construct a Handler object to communicate with logoff so as to push new messages to the Message Queue or receive messages sent by logoff from the Message Queue.
3) Message Queue: used to store messages placed by threads.
4) thread: the UI thread is usually the main thread, and Android will create a Message Queue for it when starting the program.

8. Let's talk about the principles of the mvc model and its application in android
MVC (Model_view_contraller) "model _ view_controller ". The MVC application is always composed of these three parts. Event causes the Controller to change the Model or View, or change both. As long as the Controller changes the data or attributes of Models, all dependent views are automatically updated. Similarly, as long as the Controller changes the View, the View will
Obtain data from a potential Model to refresh yourself.
View repainting and Memory leakage seem to be frequently asked questions during interviews.
1. Refresh View:
To refresh, use handle. sendmessage to send information, and then execute invaliate or postinvaliate in getmessage of handle.
2. GC Memory leakage
Cause:
1. The database cursor is not closed
2. When constructing the adapter, the cache contentview is not used
Derivation of listview optimization problems-reduce the creation of view objects, make full use of contentview, you can use a static class to optimize the process of processing getview/
3. Use recycle () to release the memory when the Bitmap object is not in use
4. the lifecycle of objects in the activity is greater than that of the activity.
Debugging method: DDMS ==> HEAPSZIE ==> dataobject ==> [Total Size]

There are other questions. You are welcome to raise this question. It can be the overall architecture and the Hal layer.
This article involves the following content:
Lifecycle of an Activity
2. Change Activity to a window: Activity attribute setting
3. Your background Activity is System
Recycling: onSaveInstanceState
4. call and call: our communication messenger-Intent
Lifecycle of an Activity
Like applications on other mobile platforms, the lifecycle of Android applications is under unified control, that is, the fate of the applications we write is in the hands of others (systems, we can't change it. We can only learn and adapt to it.
To put it simply, why is this: our mobile phone is running?
When an application calls in, it is possible to send a text message, or the application will be interrupted if there is no power available. In this case, the basic functions of the service phone are prioritized, in addition, the system does not allow you to occupy too many resources. At least ensure the phone function, so when resources are insufficient, it may be killed. To put it bluntly, the following code shows the basic lifecycle of an Activity:
Java code
Public class MyActivity extends Activity
{
Protected void onCreate (Bundle savedInstanceState );
Protected void onStart ();
Protected void onResume ();
Protected void onPause ();
Protected void onStop ();
Protected void onDestroy ();
}
The Activity you write will be as needed
To re-load these methods, onCreate is inevitable. During normal startup of an Activity, they are called in the order of onCreate-> onStart-> onResume, when the Activity is killed, the sequence is onPause-> onStop-> onDestroy, which is a complete life cycle, but someone asks
The program is running. What should I do? If a new Activity is in full screen when it is aborted: onPause-> onStop, onStart-> onResume when it is restored. If it is interrupted
In this application, if Theme is Translucent or dicent Activity, it is only onPause and restored.
OnResume.
The following describes in detail what the system is doing and what we should do:
OnCreate:
Create an interface here to initialize some data
OnStart:
In this step, the user is visible and cannot interact with each other.
OnResume:
It becomes interactive with the user (the activity stack system manages the top of these activities through stacks, and returns to the previous Activity after the pop-up stack is run)
OnPause:
This step is visible but not interactive. The system will stop animation and other CPU-consuming tasks. As you can see from the above description, you should save some of your data here, at this time, your program has a lower priority and may be reclaimed by the system. The data stored here should be read out in onResume. Note: The time for doing this method is short, because the next activity will not start until this method is complete.
Onstop:
Invisible and overwritten by the next activity
OnDestroy: This is the last method called before the activity is killed. It may be that the external class calls the finish method or the system temporarily kills the method to save space. You can use isFinishing () to judge it. If you have a Progress Dialog online task, please drop it cancel in onDestroy. Otherwise, when the thread ends, calling the cancel Method of Dialog will throw an exception.
In onPause, onstop, and onDestroy, the activity may be killed by the system in three states. To ensure the correctness of the program, you must write the code of the persistent layer operation in onPause, save all edited content to the storage medium (generally databases ). In actual work, there are also many problems due to changes in the life cycle. For example, if your application starts to run a new thread and the thread is interrupted, you need to maintain the thread, pause, kill, or roll back data, right? Because the Activity may be killed, pay attention to the variables and some interface elements used in the thread. Generally, I use the Android message mechanism [Handler, message] to handle the problem of multithreading and interface interaction. I will talk about this later, because these things are already very big recently, and I will share them with you when I clear my thoughts.

2. Change Activity to a window: Activity attribute setting
It's easy to talk about it. Some people may want to make the app something floating on the main interface of the mobile phone. It's easy to set the theme of the Activity in AndroidManifest. one sentence for defining an Activity in xml:
Xml Code
Android
: Theme = "@ android: style/Theme. Dialog"
Android: theme = "@ android: style/Theme. Dialog"
This makes your application pop up in the form of a dialog box, or Xml Code
Android: theme = "@ android: style/Theme. Translucent"
Android: theme = "@ android: style/Theme. Translucent"
It becomes translucent. [friendly reminder -. -] attributes of similar activities can be found in android. r. the AndroidManifestActivity method of the styleable class shows AndroidManifest. for more information about the attributes of all elements in xml, see android. r. styleable
The property name is mentioned above. What is the specific value in android. R. style?
You can see, for example, @ android: style/Theme. dialog "corresponds to android. r. style. theme_Dialog, (replace '_' '. '<-- Note: The content of this article is not a smiley face) and can be used in the description file.
.
3. What should I do if your background Activity is recycled by the system: onSaveInstanceState?
When Activity A of your program actively or passively runs another Activity B at run time, A will execute
Java code
Public
Void onSaveInstanceState (Bundle outState ){
Super. onSaveInstanceState (outState );
OutState. putLong ("id", 1234567890 );
}
Public void
OnSaveInstanceState (Bundle outState ){
B will come to A again after it is completed. There are two situations at this time: A is recycled, and B is not recycled, the returned A will call the onCreate () method again. The difference is that the onCreate () method is started directly with the savedInstanceState parameter. If it is not recovered, it will be onResume.
SavedInstanceState is a Bundle object. You can basically regard it as a Map object maintained by the system. You may use it in onCreate (). If onCreate () is started normally, it will not be available. Therefore, you need to determine whether it is empty when using it.
Java code
If (savedInstanceState! = Null ){
Long id = savedInstanceState. getLong ("id ");
}
If (savedInstanceState! = Null ){
Just like the official Notepad tutorial
You are editing a note, and it is suddenly interrupted. Remember the note id and you can retrieve the note according to the id, the program is complete. This also shows that your application does not need to be saved. For example, if your interface is to read a list, you do not need to remember anything special,
Maybe you need to remember the position of the scroll bar...
4. call and call: our communication messenger Intent
Intent is the intention of Intent. Intent is the intention of communication between applications. Intent will be sent when you make a call, this is the essence of loose coupling in the Android architecture and greatly improves component reusability. For example, it is very easy to click a button in your application and call someone, take a look at the code first:
Java code:
Intent intent = new Intent ();
Intent. setAction (Intent. ACTION_CALL );
Intent. setData (Uri. parse ("tel:" + number ));
StartActivity (intent); copy the code
Throwing out such an intention, the system will wake up the dialing program and make a call when it sees your intention. What reading contacts, text messages, emails, all just need to be thrown out of intent. This part is really well designed.
So what does Intent tell the system who needs to accept it?
There are two methods to use Intent. The first method is to directly describe which class is required to receive the Code as follows:
Java code
Intent intent = new Intent (this, MyActivity. class );
Intent. getExtras (). putString ("id", "1 ");
StartActivity (intent );
Intent intent = new Intent (this, MyActivity. class); intent. getExtras (). putString ("id", "1"); tartActivity (intent); copy the code
The first method is obvious. You can directly specify MyActivity as the receiver and pass some data to MyActivity. In MyActivity, you can use getIntent () to get the intent and data.
In the second method, you need to first check the intentfilter configuration in AndroidMenifest.
Xml Code
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Action android: value = "android. intent. action. EDIT"/>
<Action android: value = "android. intent. action. PICK"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Data android: mimeType = "vnd. android. cursor. dir/vnd. google. note"/>
</Intent-filter>
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Action android: value = "android. intent. action. EDIT"/>
<Action android: value = "android. intent. action. PICK"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Data android: mimeType = "vnd. android. cursor. dir/vnd. google. note"/>
</Intent-filter>
If action, data, and category are used in the configuration, you must think that intent also has these things. Will the receiver be found after a match?
Action is actually a string name of intent.
The configuration file of intent-filter above shows that this Activity can accept different actions. Of course, the corresponding program logic is different. Let's mention the mimeType, which is in
As defined in ContentProvider, If you implement a ContentProvider, you must specify mimeType to make the data available to others.
I don't know the principle. I don't want to explain it. In summary, you call another interface instead of the new interface. Instead, you can throw an intent to let the system call that interface for you, in this way, it is loose and compliant with the principle that the lifecycle is managed by the system.
If you want to know what category has and what actions Android has customized for you, visit the official link Intent.
Ps: If you want to know how to call system applications, you can take a closer look at your logcat. Do you have some information when running a program? For example:
Starting activity: Intent {action = android. intent. action. MAINcategories = {android. intent. category. LAUNCHER} flags = 0x10200000comp = {com. android. camera/com. android. camera. galleryPicker }}

Compare some set methods of Intent to know how to call them. Hope you like it :)
1. How do you optimize listview.
Ii. Refresh view, as mentioned earlier
Iii. IPC and principles
4. Multiple Android threads
5. Why do Android need to design four major components? the connection between them is not feasible without design (mainly to implement the MVC mode, but this is also the most difficult mode in java, few products can make this model very good [This Is What Technicolor's interviewer asked ])
6. service cycle and activity cycle. Let's talk about your understanding of Android internal applications, such as phone calls and contacts. There are a lot of things in the framework layer. If you are familiar with how Android works, it is very good whether you are doing application development or application framework layer development.
In terms of your project experience, highlight what difficulties you encounter, and then how to solve them! Highlight every technical point as much as possible. Of course, the interviewer sometimes asks you to create the module in this application to reflect whether you have actually done it, how many classes are used.
Occasionally, the interviewer will ask you, if you have used the unit test that comes with Android, how can you use it?
Of course, I have interviewed many companies, including tablets, mobile phones, digital TVs, and erp clients, basically, all Android is changed. If you really want to do Android, you still need to learn a lot.

In a word, there are all kinds of interviewers, and all psychological preparations should be made when you go to the interview. Both the technology and the Foundation should be solid. A person's ability to talk is also very important. In short, they are not very standard Mandarin. At least you have to make others understand what you say, and you have to make the interviewer very thorough, in this way, you will have a higher chance of getting an offer and have an advantage in salary negotiation ~~ Of course, the interviewer of a company once told me that technology is free of money, as long as you have the ability, how much money he will ask.
1. How to refresh the View?
2. What is the difference between DDMS and TraceView?
3. What should I do if the activity is recycled?
4. How to introduce C language in Java?
Reference answer:
1. View can call the invalidate () and postInvalidate () Methods to refresh
2. DDMS is a program execution viewer in which you can see information such as threads and stacks. TraceView is a Program Performance Analyzer.
3. The activity has been recycled, so there is only another one.
4. java calls the C language program and can be implemented using the JNI Interface
The above answers are for reference only. After all, my personal abilities are limited, and I will inevitably answer the wrong answers .....
Answer:
1. View is refreshed by the system (there is a loop inside the system, monitoring events, business processing, and UI painting), and postInvalidate () can be used to urge the system to refresh.
2. (I really don't know)
3. Please refer to the Activity life cycle. If it is destroy by the system, that is to say, the recycle will only start from the new start.
4. Call JNI. We recommend that you read The Java Native InterfaceProgrammer's Guide and Specification in English. For more information, see The sun website.
 
 

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.