Home> Common Problem> body text

Baidu Android interview questions sharing

藏色散人
Release: 2020-07-31 17:06:09
forward
3071 people have browsed it

Recommended: "2020 Android interview questions summary [Collection]"

1,Android dvmprocesses andLinuxprocesses,Whether the application processes have the same concept

DVMRefers to the virtual machine ofdalivk. EachAndroidapplication runs in its own process and has an independentDalvikVirtual machine instance. And eachDVMis a process inLinux, so It can be considered as the same concept.

2##、simWhat is the function of the card’sEF##sim

The card’s file system has its own specifications, mainly for communicating with mobile phones,simYou can have your own operating system,EFis used for storage and communication with mobile phones3

, what are the types of memory management in embedded operating systems and what are their characteristics?Page type, segment type, segment page, using

MMU,Virtual space and other technologies4

、What is embedded Real-time operating system, AndroidIs the operating system a real-time operating system??

The embedded real-time operating system means that when external events or data are generated, it can accept and process them at a fast enough speed, and the processing results can control production within the specified time. Process or embedded operating system that responds quickly to the processing system and controls all real-time tasks to run in a coordinated manner. Mainly used in industrial control, military equipment,
#, aerospace and other fields have strict requirements on system response time, which requires the use of real-time systems . It can be divided into soft real-time and hard real-time, andandroidis based onlinuxKernel, so it is soft real-time.

5##、How much is the longest short message?byte?

中文70(Including punctuation), English160bytes

6android# What are the types of animations in##, and what are their characteristics and differences?

Two kinds, one isTweenanimation, and the other The kind isFrameanimation.TweenAnimation, this implementation can make the view component move, enlarge, shrink and produce transparency changes; anotherFrameAnimation, the traditional animation method, is achieved by playing the arranged pictures in sequence, similar to a movie.

7handlerPrinciple of the mechanism

andriodprovidesHandlerandLooperTo meet the communication between threads.HandlerFirst in, first out principle.Looperclass is used to manage message exchange between objects within a specific thread(Message Exchange).
1
Looper:A thread can generate aLooperobject, which manages theMessage Queue(Message Queue in this thread).
2
)Handler:You can constructHandlerObject to communicate withLooperso thatpushnew messages arriveMessage Queue; or receiveLooperfromMessage QueueGet the message sent by).
3
Message Queue(Message Queue):is used to store messages put by threads.
4
) Thread:UI threadis usuallymain thread, andAndroidwill create a# for it when it starts the program##Message Queue.

8、Talking aboutmvcThe principle of the pattern, its application inandroid

MVC(Model_view_contraller)”Model_View_Controller.MVCAn application always consists of these three parts.Event(Event)results inControllerChangeModelorView, or change both at the same time. As long asControllerchanges the data or properties ofModels, all dependentViewwill be updated automatically. Similarly, as long asControllerchangesView,Viewwill get data from the underlyingModelto refresh itself.

ViewRedrawing and memory leaks seem to be questions often asked in interviews
1. Refresh View:

Usewhere you need to refresh,handle.sendmessageSend message,and then inhandlegetmessageexecutesinvaliateorpostinvaliate.

2. GCMemory leak
Occurrence:
1.
cursorof the databaseNot closed
2.
ConstructionadapterWhen,not using cachecontentview
derivativeOptimization issues oflistview-----Reduce creationviewobjects,make full use ofcontentview,You can use a static class to optimize the process ofgetview/
3. Bitmap
When the object is not in use, userecycle()Release memory
4. The life cycle of the object in activity
is greater thanactivity
Debugging method: DDMS==> HEAPSZIE==>dataobject==>[Total Size]

Life cycle of Activity
LetActivitybecome a window:ActivityProperty settings
##三Your backgroundActivityis blocked by the system
What to do with recycling:onSaveInstanceState
Call Invoked with: Our Messenger- Intent
The life cycle of Activityand other mobile phones

PlatformThe application is the same asAndroid## The life cycle of the# application is uniformly controlled, which means that the fate of the application we write is in the hands of others (system). We cannot change it, we can only learn and adapt to it.

Let me briefly explain why this is the case: when our mobile phone is running an application,, it is possible that there are incoming calls. When a text message is sent to the phone, or the battery is out of power, the program will be interrupted at this time and priority will be given to serving the basic functions of the phone. In addition, the system does not allow you to occupy too many resources. At least the phone function must be ensured,So when resources are insufficient, they may be killed. Closer to home, the basic life cycle ofActivityis as follows:

JavaCode

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(); }
Copy after login

Written by yourselfActivitywill be repeated as neededContaining these methods,onCreateis inevitable, in anActivityDuring normal startup, the order in which they are called isonCreate -> onStart ->onResume,inActivityThe order when being killed isonPause -> onStop -> onDestroy, this is a Complete life cycle, but someone asked, a call came while the program was running, what should I do with this program? It's aborted. If the newActivityis full screen when it is aborted, then:onPause->onStop, when restoring,onStart->onResume, if the one who interrupts this application is aThemeisTranslucentorDialogActivityThen it’s justonPause,when restoringonResume. Let’s introduce in detail what the system is doing and what we should do in these methods:
onCreate:
Create an interface here and do some data Initialization work
onStart:
At this step, it becomes visible and non-interactive to the user
onResume:
It becomes interactive with the user , (inactivitythe stack system manages these individuals through the stackActivity## At the top of #, after running and popping the stack, return to the previousActivity)onPause:
toThis step is visible but not interactive. The system will stop animations and other things that consumeCPUfrom the above description Already know that some of your data should be saved here,because at this time the priority of your program is reduced and it may be taken back by the system. The data saved here should be read out inonResume. Note: The time required for this method should be short, because the nextactivitywill not wait until this method is completed before startingonstop:
becomes invisible , overwritten by the nextactivityonDestroy:This is the last method called beforeactivityis killed. It may be called by an external classfinishmethod or the system temporarily kills it to save space, you can useisFinishing()To judge it, if you have aProgress Dialogturning in the thread, please check it inonDestroyCancel, otherwise when the thread ends, callDialog# Thecancel## method will throw an exception.onPause,onstop,onDestroy, in the three statesactivitymay be killed by the system. In order to ensure the correctness of the program, you mustonPause ()Write the code for the persistence layer operation to save the user-edited content to the storage medium (generallyare all databases). In actual work, there are many problems caused by changes in the life cycle. For example, if your application starts a new thread and is interrupted at this time, you still have to maintain that thread, whether to pause or kill itThe data needs to be rolled back, right? BecauseActivitymay be killed, so you must pay attention to the variables and some interface elements used in the thread. Generally, I useAndroid’s message mechanism[Handler,Message]to handle multi-threading and interface interaction question. I will talk about this later, because these things have become very popular recently, so I will share it with you after I clear my mind.

twoLetActivitybecome a window:ActivityProperty settings

Let’s talk a little more relaxedly,Some people may want to make an application that floats on the main interface of the phone. , so it’ssimple, you just need to set the theme ofActivityHere is a sentence whereActivityis defined inAndroidManifest.xml:
Xml
Code
android:theme="@android:style/Theme.Dialog"
android:theme="@android:style/Theme.Dialog"
This will make your application pop up in the form of a dialog box, orXmlCode
android:theme="@android:style/Theme.Translucent"
android:theme="@ android:style/Theme.Translucent"
willbecome translucent,[Friendly reminder-.-]Similar to this## The properties of #activitycan be found inandroid.R.styleable#AndroidManifestActivity As seen in themethod, the introduction of the attributes of all elements inAndroidManifest.xmlcan refer to this classandroid.R.styleableThe above is the attribute name, the specific value is inandroid.R.style
You can see, for example, this"@android:style/Theme.Dialog"corresponds toandroid.R.style.Theme_Dialog ,'_'Replace with'.' <--Note: This is the content of the article, not the smiley face) can be used in the description file

.three

What should you do if your background###############Activity############## is recycled by the system: ######## #######onSaveInstanceState#########

When anActivity A in your programactively or passively runs another new one during runtimeActivity BAt this timeAwill executeJavaCode
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(" id", 1234567890);
}
public void onSaveInstanceState(Bundle outState) {
B
Will come back after completionA ,There are two situations at this time, one is thatAis recycled, the other is that it is not recycled and is ReturnReceivedAwill have to be called againonCreate()method, different from direct startup, this timeonCreate()has parameters.savedInstanceState, if it has not been recovered, it will still beonResume.
savedInstanceState
is aBundleobject. You can basically understand it as amaintained by the system for you.MapObject. You may use it inonCreate(), if it starts normallyonCreateThere won't be it, so you have to check whether it is empty when using it.
Java
Code
if(savedInstanceState !=null){
long id =savedInstanceState .getLong("id");
}
if(savedInstanceState !=null){
Just like the officialNotepad# In the situation in##tutorial
, you are editing a certainnote, if it is suddenly interrupted, then put theid of thisnote##Remember, when you get up again, you can use thisidto change thatnoteTake it out and the program will be more complete. This also depends on whether your application needs to save anything. For example, if your interface is to read a list, then there is no need to remember anything in particular, oh,
Maybe you need to remember the position of the scroll bar
...

Calling and being called: our messengerIntent

SayIntent,IntentIt is this intention,Intent## A call. When a call comes,
Intent will be sent,This is

Android

The essence of loose coupling of the architecture greatly improves the reusability of components. For example, if you want to click a button in your application to call someone, it is very simple. 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 code
Throw such an intention, and the system will wake up the phone dialer after seeing your intention and make a call. To read contacts, send text messages, or emails, you just need to throwintent. This part is really well designed.Then
Intent#How to tell the system who needs to accept it What about him? There are usually two ways to use

Intent

. The first is to directly indicate which class is needed 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 code############
The first way is obvious, directly specifyMyActivityas the recipient,and passed some data toMyActivity, inMyActivityYou can usegetIntent()to get thisintentand data.
The second option is to take a look atAndroidMenifestintentfilteris configured with
Xml
code

             

这里面配置用到了action, data, category这些东西,那么聪明的你一定想到intent里也会有这些东西,然后一匹配不就找到接收者了吗?action其实就是一个意图的字符串名称。
this sectionintent-filterThe configuration file shows that this Activity can accept different Action , of course the corresponding program logic is also different,Mention that mimeType,It is defined in ContentProvider. If you implement one yourselfContentProviderYou know, you must specify mimeType to allow the data to be used by others. I don’t know if the principle is clear. To sum up, you don’t call other interfaces directlynewthat interface, but by throwing aintent, let the system help you call that interface, this is so loosely coupled, and it conforms to the principle that the life cycle is managed by the system. If you want to know what category has, Android is pre-customized for you actionWhatever, etc., please visit the official link in personIntentps: Students who want to know how to call system applications can take a closer look at your logcat to see if there is some information every time you run a program, such as :

Starting activity: Intent {action=android.intent.action.MAINcategories={android.intent.category.LAUNCHER}flags=0x10200000comp={com.android.camera/com.android.camera.GalleryPicker} }
Copy after login

再对照一下Intent的一些set方法,就知道怎么调用咯,希望你喜欢:)

One,listviewHow did you optimize it? .
two,Refresh of view, as mentioned before
##三,IPC##and principle
##Four,##AndroidMulti-threading
#Five,
AndroidWhy design4Large components, the connection between them, can it be done without designing (mainly to realize theMVCpattern, However, the most difficult mode injavais also this. Very few products can do this mode well [The interviewer at Technicolorasked this])Six, the cycle ofservice,activitycycle, tell me about yourAndroid# Understanding of internal applications, such as phone,and contacts applications. There are a lot of things in the framework layer, so it’s better to read more and be familiar with howAndroidis done. Whether you are doing application development or application framework layer development, it is very beneficial.
This is your project experience, highlighting the difficulties you encountered and how you solved them! Try to highlight each technical point. Of course, the interviewer will sometimes ask you questions such as which module you used in this application and how many classes you used to show whether you have actually done it. Occasionally, some interviewers will ask you, have you used the unit test that comes withAndroid, and how do you use it? Of course, I have interviewed many companies, some of which are making tablets, mobile phones, digital TVs, and some of which are making clients likeerp, etc., out of the The first three are basically to change all theAndroid. If you really want to doAndroid, everyone still has a lot to learn. In summaryIn a word, there are all kinds of interviewers. When you go for an interview, you must be mentally prepared, whether it is technical or basic. solid. A person's conversational ability is also very important. In short, it is not very standard Mandarin.At least what you say must be understood by others, and you must make the interview The officer explained it very thoroughly, so you have a greater chance of getting anoffer, and you will also have an advantage in negotiating salary~~Of course, an interviewer from a company once told me that technologydoes not spare money, as long as you have the ability, no matter how much it is He invited them all.

1.ViewHow to refresh?
2. What is the difference between DDMS
andTraceView?
3. What should I do if my activity
is recycled?
4.
How to introduce# inJava##Clanguage?
Reference answer:1.View
can be calledinvalidate()andpostInvalidate()These two methods refresh2.DDMS
is a program execution viewer, in which you can see information such as threads and stacks,TraceViewis the program performance analyzer3. activity
is recycled, then there is no choice but to start a new one4.java
To call theClanguage program, you can useJNIinterface to implement
The above answer is for reference only. After all, my personal ability is limited. Well, it is inevitable that the answer will be wrong, haha...Answer:
1. View
is subject to system refresh (there is a loop inside the system to monitor events and do business Processing, drawingUI), you can usepostInvalidate()to prompt the system to refresh .
2.
(I really don’t know)
3.
Please refer to theActivitylife cycle. If it isdestroy# by the system, In other words, the only way to recycle is to#start
4.
Call viaJNI. It is recommended to read "The Java Native InterfaceProgrammer's Guide and Specification", English version, fromsunDownload the website.

The above is the detailed content of Baidu Android interview questions sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!