Baidu's Android recruitment interview questions

Source: Internet
Author: User
General simple question

1. is the process of Android dvm 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 use 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 ).

  • Loue: A thread can generate a loue object to manage the Message Queue (Message Queue) in this thread ).
  • 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.
  • Message Queue: used to store messages placed by threads.
  • Thread: the UI thread is usually the main thread, and a Message Queue is created for the Android Startup Program.

8. Let's talk about the principles of the MVC pattern, which is used 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 retrieve data from the potential Model to refresh itself.

View repainting and Memory leakage

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:

  • The database cursor is not closed.
  • When constructing the adapter, the cache contentview is not used. Optimization of the derived listview: reduces the number of objects for creating a view and makes full use of contentview. You can use a static class to optimize the getview process.
  • When the Bitmap object is not in use, use recycle () to release the memory.
  • The lifecycle of objects in an activity is greater than that of an activity.
Activity

1. Activity Lifecycle

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.

Simply put, Why is it like this: our mobile phone is running. When an application is running, it is possible to call in and send a text message, or when there is no power, the program will be interrupted, give priority to the basic functions of the service phone. In addition, the system does not allow you to occupy too many resources. At least ensure the phone function. Therefore, when resources are insufficient, the phone may be killed. To put it bluntly, the following code shows the basic lifecycle of an Activity:

1 public class MyActivity extends Activity{
2     protected void onCreate(Bundle savedInstanceState);
3     protected void onStart();
4     protected void onResume();
5     protected void onPause();
6     protected void onStop();
7     protected void onDestroy();
8 }

The activities you write will reload these methods as needed. onCreate is inevitable. During the 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. This is a complete life cycle, but someone asks, the program is running and the phone is called, what should I do with this program? If a new Activity is in full screen when it is aborted: onPause-> onStop, onStart-> onResume when it is restored, if the application is interrupted by an Activity whose Theme is Translucent or dicent, it is only onPause and onResume is restored. The following describes in detail what the system is doing and what we should do:

  • OnCreate: Create an interface to initialize data.
  • OnStart: In this step, the user can see 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. After the stack is run, it returns to the previous Activity ).
  • 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 things in this method is short, because the next activity will not start until the method is complete.
  • Onstop: it becomes 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. So it's easy to set the theme of the Activity in AndroidManifest. one sentence for defining an Activity in xml:

1 android:theme="@android:style/Theme.Dialog"
2 android:theme="@android:style/Theme.Dialog"

This makes your application pop up in the form of a dialog box, or

1 android:theme="@android:style/Theme.Translucent"
2 android:theme="@android:style/Theme.Translucent"

It becomes translucent. Similar properties of this activity 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 refers to the property name. The specific value is in android. r. style, such as @ android: style/Theme. dialog "corresponds to android. r. style. theme_Dialog, (replace '_' '. ') can be used in the description file. You can find the corresponding relationship between the class definition and 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 runtime, A will execute the Java code:

1 public void onSaveInstanceState(Bundle outState) {
2      super.onSaveInstanceState(outState);
3      outState.putLong("id"1234567890);
4 }

After B is completed, A will be returned. At this time, there are two situations: A is recycled, and A is not recycled. A will call onCreate () again () method. The difference is that the parameter savedInstanceState is included in onCreate (), and onResume is enough if it is not recovered.

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.

1 if(savedInstanceState !=null){
2      long id =savedInstanceState.getLong("id");
3 }

Just like in the official Notepad tutorial, if you are editing a note that is suddenly interrupted, remember the note id, then, you can extract the note according to the id, and the program will be 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. Oh, 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 phone 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:

1 Intent intent = new Intent();
2 intent.setAction(Intent.ACTION_CALL);
3 intent.setData(Uri.parse("tel:"+ number));
4 startActivity(intent);

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:

1 Intent intent = new Intent(this,MyActivity.class);
2 intent.getExtras().putString("id","1");
3 startActivity(intent);
4 Intent intent = newIntent(this,MyActivity.class);intent.getExtras().putString("id","1");tartActivity(intent);

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.

01 <intent-filter>
02 <action android:name="android.intent.action.VIEW" />
03 <action android:value="android.intent.action.EDIT" />
04 <action android:value="android.intent.action.PICK" />
05 <category android:name="android.intent.category.DEFAULT"/>
06 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
07 </intent-filter>
08 <intent-filter>
09 <action android:name="android.intent.action.VIEW"/>
10 <action android:value="android.intent.action.EDIT" />
11 <action android:value="android.intent.action.PICK" />
12 <category android:name="android.intent.category.DEFAULT" />
13 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
14 </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 in the above section shows that this Activity can accept different actions. Of course, the corresponding program logic is different. Let's mention the mimeType, which is defined in ContentProvider, if you implement a ContentProvider by yourself, you must specify mimeType to enable data to be used by 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 is and what Android has for your pre-defined actions, visit the official link Intentps: 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 :)

Supplement

1. How do you optimize listview.

2. Refresh the view, as mentioned earlier.

3. IPC and its principles.

4. Multiple Android threads.

5. why should Android 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 well.

6. The service cycle, activity cycle, and 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.

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.