I need to find a job in the near future, so the most important task is to prepare for the interview, not unprepared battle. Only if you are fully prepared, then the opportunity you want may have the chance to come into your arms.

I will prepare for the interview learning process recorded, convenient for their own review at the same time also hope to give a job to find some help partners. The outline prepared by the author is as follows

So let’s get started, QAQ

1. What is ANR? What is the reason for it? How to solve it in actual development?

  • ANR in Android means the application is not responding. For some events that need to be completed within a certain time, if there is no effective response within this time range, will cause ANR.
  • (1) The more common causes are a large number of time-consuming operations on the main thread (2) a deadlock caused by multi-threaded operations, the main thread is locked (3) system resources are exhausted (pipe, CPU, IO)
  • In actual development, ANR is difficult to find problems from the code. When ANR occurs, the system will generate a trace.txt text log file, which can be analyzed to locate the problem.

Reference: Android Development Art Exploration P496

Extension:

To be precise, the ANR mechanism can be divided into two parts:

  • ANR monitoring mechanism. Android has a monitoring mechanism for different ANR types (Broadcast, Service, InputEvent).
  • ANR reporting mechanism. After ANR is detected, the ANR dialog box and output logs (process function call stack, CPU usage, etc.) need to be displayed.

A general type of ANR

1. KeyDispatchTimeout (common) : ANR occurs when input events are not processed within 5S.

2. BroadcastTimeout: broadcastReceiver Does not complete processing within 10S. ANR occurs. Background Broadcast: ANR does not occur on onReceiver within 60 seconds.

3. ServiceTimeout: foreground Service: onCreate, onStart, onBind and other life cycles are not completed within 20s ANR occurs. Background Service: onCreate, onStart, onBind and other life cycle does not complete processing within 200s ANR occurs

4. ContentProviderTimeout: ANR occurs if ContentProvider does not complete processing within 10S

Refer to this article

Talk about Activity and Fragment lifecycles

What’s the difference between onStart and onStop, onPause and onResume?

The most obvious difference is that onStart and onStop are called from whether the Activity is visible, while onResume and onPause are called from whether the Activity is in the foreground.

Can onPause perform time-consuming operations?

No, time-consuming operations should be done in onStop as much as possible so that the new Activity can be displayed and brought to the foreground as soon as possible.

Note: The Activity at the top of the stack must be onpaused before a new Activity can be started.

3. Life cycle of the Activity when switching between horizontal and vertical screens

  • When you do not set android:configChanges for an Activity, you will recall each lifecycle when you change the screen, once when you change landscape, and twice when you change portrait
  • When you set android:configChanges=”orientation” to an Activity, you will still invoke each lifecycle when you cut the screen, only once when you cut the landscape and portrait
  • Set up the Activity of the android: configChanges = “orientation” | keyboardHidden | screenSize “, cut the screen each life cycle will not call again, will only implement onConfigurationChanged method

When a system configuration change occurs, such as a vertical or horizontal screen switch, its onPause, onStop, and onDestroy functions are called, and the Activity terminates abnormally. The system calls onSaveInstanceState to save the state of the current Activity before the onStop method. When the screen direction is switched back, the onCreate, onStart, and onResume methods are called in turn, and the previously saved data can be retrieved and restored in onRestoreInstanceState and onCrate.

Note: onSaveInstanceState is only called if the Activity has been terminated abnormally.

4. The level of processes in Android and their differences

  • Foreground process: This process is the Activity that interacts with the user or the Service that the Activity uses. It has the highest priority and is the last to be killed.
  • Visible process: Can be an Activity in the paused state or a Service bound to it, visible to the user but not interoperable, and has a lower priority than foreground processes.
  • Service process: a Service that the system does not kill until foreground and visible processes are dead.
  • Background process: A program that is stopped by the onStop method and is the first to be killed when the system runs out of memory.
  • Empty process: a process that does not contain application components. The only reason to keep such processes is to cache them so that they can start faster the next time a component tries to run it. Systems often kill process caches to balance the overall system cost between them and the underlying kernel caches.

5. What new features do you know about the Android version?

I don’t know much about this, Android5.0 has a MaterialDesign style. Dynamic rights management for Android6.0. Split screen multitasking for Android7.0, picture in picture for Android8.0.

Android5.0 new features

  • MaterialDesign Design style
  • Support for multiple devices
  • Supports 64-bit ART VMS

Android6.0 new features

  • Dynamic Rights Management
  • Support quick charging switch
  • Support folder drag and drop applications
  • Added professional mode to the camera

Android7.0 new features

  • Split screen multitasking
  • Enhanced Java8 language patterns
  • Night mode

Android8.0 new features

  • Picture in picture
  • Notify the logo
  • Autofill frame
  • System optimization
  • Background restrictions
  • And so on and so forth