Once an unconventional maker OPPO interview experience (text postscript to a large number of interview questions)

Author: AffyFei

REVIEW

Normally manufacturers to interview some of the underlying principles should ask, but the interview was counterintuitive to ask some basic, it also reminds us not to lose the foundation. End of the article there is a lot of face questions article, we remember to see, experience is the author of this article AffyFei, not me, look at the following text:


This morning attended the interview in Shenzhen OPPO technology development engineers, the whole interview process is not very smooth. The interviewer did not ask some very profound underlying principle, the basic foundation and infrastructure are some of Java in Android four components, but I did not value highly their theoretical foundation in the development process, resulting in many knowledge points are forgotten. The interview process takes one hour, thanks to the two interviewer taken the trouble to give me a hint, on the one hand so that I can in retrospect those forgotten knowledge, it also eased the atmosphere of embarrassment. . .

By the way, OPPO security work is still done quite strict, Houhai Zhuo into the center of the building before the need to apply for a temporary pass to get in. And also you need to register before the interview, and the phone's front and rear camera gave taped together to conduct interviews. Without further ado, here is divided into two parts summary of what knowledge the technical interview.

Java side

1. How to understand Java polymorphic? Among them, overloading and rewrite what's the difference?

Polymorphism is the ability to have several different forms or manifestations of the same behavior, polymorphism is the same interface, using different instances and perform different operations, polymorphism is determined only during program run, a variable reference point to which it is going examples of object classes, this reference variable method calls made in the end is which class methods implemented.

Polymorphism three necessary conditions are present: inheritance, rewrite, references to the parent class subclasses reference.

Three polymorphic implementation is: rewriting, interfaces, abstract classes and abstract methods.

Difference rewrite (Override) and heavy (Overload) of

2. JVM memory to talk about zoning? Which part is thread-public, part of which is private?

JVM memory area can be divided into two categories: private and regional threads and threads common to the area. Thread private areas: program counter, JVM virtual machine stack, native method stacks; common thread area: heap, the method area, runtime constant pool.

  • A program counter register PC may be called. Each thread has a private program counter, any time there is only one thread is executing a method, which is called the current method. The program counter is stored in the JVM instruction address the current method. When the CPU instructions to be executed require address of the instruction currently to be executed where the storage unit from the program counter, and acquires the instruction address obtained after obtaining the instruction, the program counter is automatically incremented by one, or transfer the pointer obtained according to the following an instruction address, and so on, until completion of all instructions are executed.
    JVM virtual machine stack. Thread creation time will create a virtual machine within the thread stack, stack a store with a stack frame, corresponding to a call to a method. JVM stack virtual machine with two operation, respectively push and outbound. Stack frame stored in the local variable table (Local Variables), running the operand stack (Operand Stack), points to the current method belongs to the class of the time constant pool reference (Reference to runtime constant pool), the method returns the address (Return Address) and some additional additional information.
  • Native method stacks. Java native method stacks and stacks of the role and principles are very similar. The difference is only Java stack is a Java implementation of methods for the service, and the local stack method is to implement a local method (Native Method) services. In the JVM specification, there is no place for this specific method development and data structure as a mandatory requirement, the virtual machine is free to implement it. Directly put into one native method stacks and stacks HotSopt Java virtual machine.
    stack. Heap memory management is the core area, used to store an object instance. Almost all the created object instances are directly assigned to the heap. So heap of garbage collection is the main area, the garbage collector will have a heap more subdivisions, the most common is to heap is divided into the old and the new generation's. java heap is not allowed continuous physical memory space, as long as continuous logical can. If there is no space to complete the heap OutOfMemoryError exception will be thrown instance assignment can not be extended.
  • Methods area. A method as heap region all the threads of the shared memory area for storing class information of the virtual machine has been loaded, a constant, static variables, the time compiler to compile code and other data. In addition to the Class file fields, methods, and interface description information and the like, as well as a constant pool information for literal symbols generated during storage and compile reference.

In fact, in addition to the program counter, the other part will take place OOM.

  • stack. OOM will happen usually happens in the heap, probably the most common cause of OOM is a memory leak.
  • JVM virtual machine stack and native method stacks. When we write a recursive method, this method is not recursive loop termination condition will eventually lead to StackOverflow errors. Of course, if the stack space expansion fails, the OOM will also occur.
  • Methods area. The method area is now substantially less OOM will happen, but at too early loading class information memory OOM situation is to occur.

Usage 3.final keyword?

You may be modified final class variables and methods. Modified class represents the class can not be inherited. This variable represents the modified variables can not be changed. This method represents a modification methods can not be overwritten (override).

4. deadlock is caused by how? How to position Deadlock

A task waiting for another task, which in turn is waiting for other tasks, so keep on going until the job is on the chain and the first task is waiting to release the lock. This has been a continuous loop between tasks waiting for each other, no thread can continue. This is called deadlock. When the following four conditions are met, the deadlock:

(1) mutually exclusive conditions. Resources task used in at least one is not shared.

(2) mission must hold a resource while waiting for access to resources and the other is occupied by other tasks.

(3) resources can not be usurped.

(4) There must wait cycle. A task is waiting for resource held by another task, which in turn is waiting for resources held by other tasks, so keep on going until a task is waiting for resources held by the first task that we all It is locked.

To resolve the deadlock, we must break the four conditions above one of them. In the program, the most likely to break the often fourth condition.

5. How to upgrade the database? SQLite additions and deletions to change search of basic sql statement?

/***Createahelperobjecttocreate,open,and/ormanageadatabase.*Thismethodalwaysreturnsveryquickly.Thedatabaseisnotactually*createdoropeneduntiloneof{@link#getWritableDatabase}or*{@link#getReadableDatabase}iscalled.**@paramcontexttousetoopenorcreatethedatabase*@paramnameofthedatabasefile,ornullforanin-memorydatabase*@paramfactorytouseforcreatingcursorobjects,ornullforthedefault*@paramversionnumberofthedatabase(startingat1);ifthedatabaseisolder,*{@link#onUpgrade}willbeusedtoupgradethedatabase;ifthedatabaseis*newer,{@link#onDowngrade}willbeusedtodowngradethedatabase*/publicSQLiteOpenHelper(Contextcontext,Stringname,CursorFactoryfactory,intversion){this(context,name,factory,version,null);}publicSQLiteDatabasegetWritableDatabase(){synchronized(this){returngetDatabaseLocked(true);}}privateSQLiteDatabasegetDatabaseLocked(booleanwritable){.......db.beginTransaction();try{if(version==0){onCreate(db);}else{if(version>mNewVersion){onDowngrade(db,version,mNewVersion);}else{onUpgrade(db,version,mNewVersion);}}db.setVersion(mNewVersion);db.setTransactionSuccessful();}finally{db.endTransaction();}}

SQLiteOpenHelper constructor, the version of a parameter included. The parameter that is the version of the database. Therefore, we upgrade the database can be achieved by modifying version. When a version larger than the original database version, onUpgrade () will be triggered, you can write the database upgrade logic in this method. Specific examples may refer to the database upgrade logic here.

Commonly used SQL CRUD:

By: INSERT INTO table_name (column 1, column 2, ...) the VALUES (value 1, value 2, ....)
Delete: DELETE FROM table name WHERE column name = value
change: UPDATE table name SET column name = the new value WHERE column name = a value
check: SELECT column names (the symbol * is the wildcard) FROM table name

ps: the operation data table is: ALTER TABLE. The statement added to the existing list, modify, or delete columns.
The ADD TABLE table_name column_name DataType the ALTER
the ALTER TABLE table_name DROP the COLUMN column_name
the ALTER TABLE RENAME table_name_old the TO table_name_new

Android respect

1.Broadcast classification? Orderly and disorderly? Sticky, non-tacky? Local broadcast?

  • Radio broadcasts can be divided into orderly and disorderly broadcast, local broadcast, sticky broadcast. Wherein the broadcast transmission by random sendBroadcast (intent), ordered by broadcast transmission sendOrderedBroadcast (intent).
  • Ordered broadcast.
    (1) ordered by priority broadcast may be adjusted priority ranges from -1000 to +1000, the default is 0, the higher the priority larger the value, the higher the priority in the priority of a broadcast response.
    (2) abortBroadcast () may terminate the propagation of the broadcast, the shield of lower priority, attention only take effect orderly broadcast.
    (3) Broadcast ordered such setResultData (), getResultData (), in the communication process, the new set of data may occur in the data dissemination
  • About local broadcast, you can view this article. In general, local broadcast through the built-in LocalBroadcastManager Handler to achieve, just use the match function IntentFilter, as to BroadcastReceiver replaced by other interfaces does not matter, by the way classes and take advantage of the ready-made concept only. Stored in the register () and the time corresponding to the IntentFilter BroadcastReceiver, and find the corresponding Intent BroadcastReceiver in the sendBroadcast () when the message is then sent by Handler, triggering executePendingBroadcasts () function, then the corresponding call onReceive BroadcastReceiver in the latter () method.
  • Message viscosity: the viscosity after the message has been transmitted message exists in the inside of the container system, the processor waiting for the processing corresponding to, if not the processor temporarily process the message in the message has been in a waiting state inside the container, if the viscosity is broadcast Receiver destruction, will automatically receive a message when the data then the next reconstruction. (In deprecated android 5.0 / api 21, are no longer recommended, as well as the corresponding broadcast orderly viscosity, has also been deprecated)

The 2.Android event delivery mechanism?

When our finger touches the screen, the event in accordance with the Activity-> ViewGroup-> View this process to reach the final touch response View event. In the event the distribution process, involving the three most important methods: dispatchTouchEvent (), onInterceptTouchEvent (), onTouchEvent. Our fingers touch the screen, will trigger a Action_Down type of event, the current page Activity will first make the appropriate, that will come dispatchTouchEvent Activity in the method (). In this method has the following two internal logic:

  • Call getWindow.superDispatchTouchEvent ().
  • Returns true if the step directly returns true; otherwise return their onTouchEvent (). Obviously, when getWindow.superDispatchTouchEvent () returns true, it indicates that the current event has been consumed, without calling onTouchEvent; otherwise, on behalf of the incident has not been processed, so you need to call onTouchEvent Activity for processing.
    As we all know, getWindow () returns PhoneWindow, and therefore calls on the PhoneWindow in superDispatchTouchEvent nature of this code (). The latter is actually called mDecor.superDispatchTouchEvent (event). The mDecor is DecorView, it is a subclass of FrameLayout. SuperDispatchTouchEvent in DecorView in the (event) is called in super.dispatchTouchEvent (). Therefore, the call is essentially ViewGroup of dispatchTouchEvent ().

Here, the event has passed from Activity to the ViewGroup. Next, we analyze ViewGroup.
In dispatchTouchEvent ViewGroup () of the logic is as follows:

  • By onInterceptTouchEvent () to determine whether the current ViewGroup interception default ViewGroup are not blocked;
  • If blocked, then return their onTouchEvent ();
  • If not intercepted, according child.dispatchTouchEvent () Returns the value of the determination. If it returns true, then return true; otherwise return their onTouchEvent (), where up to achieve the transfer unprocessed events.

Typically, ViewGroup of onInterceptTouchEvent () returns false, said they did not intercept. It should be noted that the sequence of events, events such as Down, Move Up events ... events, from Down to Up is a complete sequence of events, from the corresponding finger pressed to lift this series of events, if ViewGroup intercepted Down event, then the subsequent events will be given to this onTouchEvent ViewGroup of. If the interceptor is not ViewGroup Down event, the Down View will deal with before the event to send a Action_Cancel type of event, notify child View this subsequent sequence of events has been taken over ViewGroup, child View previous state can be restored.

To give a common example: there are a lot of Button in a Recyclerview, we first pressed a button, and then slide some distance and then release, this time Recyclerview will follow the slide, and will not trigger the button's click event. In this example, when we press the button, the button to Action_Down received event, a subsequent sequence of events under normal circumstances should the process of this button. But we slid some distance, then Recyclerview aware that this is a slide operation to intercept this sequence of events, go its own onTouchEvent () method, is reflected in the list of slides on the screen. Then press the button while still in the state, so it is necessary to send a Action_Cancel in time to intercept before the notification button to restore the state.

View event distribution will eventually come to the dispatchTouchEvent () in. In View of dispatchTouchEvent () does not onInterceptTouchEvent (), where it is easy to understand, View no child, there would be no interceptions. View of dispatchTouchEvent () return directly to their onTouchEvent (). If onTouchEvent () returns true representative of the event is consumed, otherwise the event would not pass up spending until View processed the event or have not consume, eventually returned to the onTouchEvent Activity () terminates.

Sometimes someone will confuse onTouchEvent and onTouch. First of all, these two methods are in View of dispatchTouchEvent () in:

  • TouchListener direct return true if not null, and the View is enable, and onTouch returns true, are met, onTouchEvent able to get () method.
  • Otherwise, it will trigger onTouchEvent (). Therefore onTouch priority to get the event onTouchEvent discretion.

Finally, attach a flow chart summary:

3.Handler principle?

Handler also closely related to the Message, MessageQueue, Looper.

  • Message. Message There are two key members of variables: target, callback:
    (1) target. Handler is sending messages
    (2) callback. Incoming Runnable types of tasks when calling Handler.post (Runnable). the nature of post event also created a Message, assign we pass this runnable Message to the callback creation of this member variable.
  • MessageQueue. Message queue for storing messages, which focus on next () method, which returns the next message to be processed.
  • Looper. Looper poller message is actually connected to the core and Handler message queue. I want to create a thread in a Handler, first by Looper.prepare () to create Looper, then had to call Looper.loop () to open polling.
    (1) prepare (). This method does two things: First () Gets the current thread Looper by ThreadLocal.get, if not empty Throws RuntimeException. Otherwise, create Looper, and by ThreadLocal.set (looper) the current thread Looper just created bindings. It is worth noting that the above message queue created in fact take place in the constructor's Looper.
    (2) loop (). This method opens up the entire event polling mechanism. Its essence is to open an infinite loop, constantly getting the message msg method MessageQueue by the next (). Calls msg.target.dispatchMessage get the message () to do the processing. In summary it is calling handler.dispatchMessage ().
  • Handler. Handler focus send messages and process the message.
    (1) sends a message. In fact, in addition to sending messages and post sendMessage there sendMessageDelayed and postDelayed and so in different ways. But their essence is called sendMessageAtTime. Call enqueueMessage in sendMessageAtTime this method. EnqueueMessage do two things in this approach: implement a message handler bound by the current msg.target = this. Queue.enqueueMessage then realized the message into the team.
    (2) processing messages. The core message processing is actually dispatchMessage () this method. This method which is very simple logic, first determines whether msg.callback null, and if not empty this is executed runnable. If it is empty it will execute our handleMessage method.

There are several situations 4.ANR appear? ANR how to analyze and solve the problem?

ANR (Application Not responding). Android, the main thread (UI thread) falls within a predetermined time of the corresponding work is not processed, it will appear ANR. Specifically, ANR will appear in the following cases:

(1) the input event (the keys and touch event) has not been treated in 5s

(2) BroadcastReceiver events (onRecieve method) within the specified time not processed (foreground broadcast to 10s, backstage broadcast for the 60s)

(3) service foreground 20s background 200s did not complete the boot

(4) ContentProvider to publish not be completed within 10s

ANR problem analysis, requires a combination of Log and trace files.

5. What are memory leaks scene? Memory leak analysis tools to use?

Common memory leaks are:

  • Singleton pattern memory leaks caused.
  • Static variables resulting in memory leaks.
  • Non-static inner classes due to memory leaks.
  • When you use resources, caused by a memory leak is not timely closed.
  • Use animation property caused by a memory leak.
  • Webview lead to memory leaks.

As for the memory leak detection, commonly used tools LeakCanary, MAT (Memory Analyer Tools), Android Studio comes with Profiler. For the use of, a lot of online tutorials, self-inspection, by reference the following two:

Three uses, MAT

At the same time accompanied by the official Android Profiler Tutorial

6. How to achieve optimization to start, what tools can use?

Highlighted the systrace this tool, detailed usage can refer to the following articles:
https://blog.csdn.net/Kitty_Landon/article/details/79192377
https://www.cnblogs.com/baiqiantao/p/7700511.html
https://blog.csdn.net/xiyangyang8/article/details/50545707
https://blog.csdn.net/cxq234843654/article/details/74388328

7. What are the common design patterns? Whether you understand the chain of responsibility pattern?

Singleton, observer pattern, the factory mode, the builder pattern, pattern configured by, intermediary mode, bridge mode, the adapter mode and the like.

to sum up

Android video learning PDF + Architecture + + source code documentation interview notes

Now look back and ask the question is not difficult, just a chain asked out a lot of details related knowledge. Seen in this light, the daily development also need to pay attention to the foundation. Especially for the development experience is 1--5 years Android Developer, the majority of the interviewer examined whether the firm is the foundation of knowledge, communication skills, ability to sum up. Although this interview yellow, but after all, a very good experience.

In this I also share a big brother himself included finishing the Android architecture study PDF + Video + Interview + document source notes , as well as advanced technical architecture Advanced Brain Mapping, Android interview with thematic development, advanced materials advanced architecture to help you enhance learning Advanced, saving everyone time online in search of information to learn, you can also share with close friends studying together

If you have a need, you can point like + comment , concern me , plus Vx: 15388039515 (Note CSDN, need information)

Published 200 original articles · won praise 83 · views 70000 +

Guess you like

Origin blog.csdn.net/weixin_45258969/article/details/103996239