It's cool and cool, big factory through train!

clhcowboy 2021-08-31 14:12:09 阅读数:365

cool cool big factory train

When interviewing for a programmer position , We often need to go through a programming interview process , Employers will use this to test the technical strength of the interviewers . However , Sometimes these technical problems have little to do with our actual work , This may also bring a lot of pressure to our programming interview preparation stage . So I wrote this article , I believe it can help programmers who are about to enter the workplace .


  • 1. How to Android Application for performance analysis

  • 2. When will it cause memory leaks

  • 3. How to avoid OOM abnormal

  • 4.Android How to catch uncaught exceptions in

  • 5.ANR What is it? ? How to avoid and solve ANR( important )

  • 6.Android How to communicate between threads

  • 7.Devik process ,linux process , The difference between threads

  • 8. Describe the android System architecture

  • How the application limits memory ? How should we use memory properly ?

  • 10. sketch android What are the application structures

  • 11. Please explain Android The difference between program runtime permissions and file system permissions

  • 12.Framework How and how it works ,Activity How to generate a view Of , What is the mechanism

  • 13. What's the difference between multithreading communication and multiprocessing communication , How to realize the difference

  • 14.Android Screen adaptation

  • 15. What is? AIDL And how to use it

  • 16.Handler Mechanism

  • 17. Event distribution mechanism

  • 18. The sub thread sends a message to the main thread to update UI, except handler and AsyncTask, What is the

  • 19. Can I new handler? Why?

  • 20.Android What are the types of animation in , What are their characteristics and differences

  • 21. How to modify Activity Enter and exit animation

  • 22.SurfaceView & View The difference between

  • 23. What frameworks have been used in development 、 platform

  • 24. Used those customizations View

  • 25. Custom control : The process of drawing a circle

  • 26. Custom control : The realization process of Ferris wheel

  • 27.GridLayout Use

  • 28. The realization process of flow layout

  • 29. Third party landing

  • 30. Third party payment

  • 31. Process keeping alive

One 、 performance optimization

1. How to Android Application for performance analysis

android The main response speed of performance and UI Refresh speed .

You can refer to the blog :Android Introduction to system performance tuning tools

First of all, in terms of the time-consuming function , There is a tool TraceView This is a androidsdk My own job , Used to measure function time consuming .

UI Analysis of layout , There can be 2 block , One piece is Hierarchy Viewer You can see View The layout level of , And each View Refresh load time .

That way you can quickly locate that piece layout & View Longest time .

And through customization View To reduce view The level of .

2. When will it cause memory leaks

Memory leaks are a hassle .

When will there be a memory leak ? The root cause of memory leaks : Long life objects hold short life objects . Short period objects cannot be released in time .

1. Static collection classes cause memory leaks

Mainly hashmap,Vector etc. , If it's a static set These collections are not in time setnull Words , Will always hold these objects .

**2.**remove Method cannot delete set Set Objects.hash(firstName, lastName);

After testing ,hashcode After modification , There is no way remove 了 .

**3.**observer When we use the monitor , Tend to be addxxxlistener, But when we don't need it , forget removexxxlistener, It's easy to memory leak.

The radio didn't unregisterrecevier

**4.** Various data links are not closed , database contentprovider,io,sokect etc. .cursor

**5.** Inner class :

java Inner class in ( Anonymous inner class ), Will hold a strong reference to the host class this.

So if it is new Thread such , Background thread operation , When the thread does not end execution ,activity Will not be recycled .

Context References to , When TextView And so on hold context references . If there is static drawable, It will cause the memory to be unable to be released .

**6.** Single case

Single case Is a global static object , When holding a replicated class A yes ,A Can't be released , Memory leak.

3. How to avoid OOM abnormal

First OOM What is it? ?

When the procedure needs to apply for a paragraph “ Big ” Memory , But virtual machines can't be delivered in time , Even if I did GC After operation

This will throw OutOfMemoryException That is to say OOM

Android Of OOM What about? ?

In order to reduce the number of individual APP The impact on the whole system ,android For each app Set a memory limit .

public void getMemoryLimited(Activity context)
ActivityManager activityManager =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

HTC M7 Actually measured ,192M ceiling .512M In general ,192M That's the ceiling , But because of some special circumstances ,android Allow the use of a larger RAM.

How to avoid OOM

Reduce the use of memory objects

**1.**ArrayMap/SparseArray Instead of hashmap

**2.** To avoid the android It uses Enum

**3.** Reduce bitmap Memory footprint

  • inSampleSize: Zoom ratio , Before loading pictures into memory , We need to work out an appropriate scale first , Avoid unnecessary large image loading .

  • decode format: Decoding format , choice ARGB_8888/RBG_565/ARGB_4444/ALPHA_8, There is a big difference .

**4.** Reduce the size of resource images , Too large pictures can be considered to be loaded in sections

Reuse of memory objects

Reuse of most objects , It's all about using object pools .

**1.**listview/gridview/recycleview contentview Reuse of

**2.**inBitmap Reuse of properties for memory objects ARGB_8888/RBG_565/ARGB_4444/ALPHA_8

This method is very useful under certain conditions , For example, when loading thousands of pictures .

**3.** To avoid the ondraw Method inside new object

**4.**StringBuilder Instead of +

4.Android How to catch uncaught exceptions in



The key is to achieve Thread.UncaughtExceptionHandler

And then it's in application Of oncreate Register inside .

5.ANR What is it? ? How to avoid and solve ANR( important )

ANR->Application Not Responding

That is to say, within the prescribed time , No response .

Three types of :

1). KeyDispatchTimeout(5 seconds) — The main type of key or touch event does not respond within a specific time

2). BroadcastTimeout(10 seconds) —BroadcastReceiver Can't finish processing in a certain time

3). ServiceTimeout(20 seconds) — Small probability type Service Can't finish processing in a certain time

Why does it time out : There is no opportunity to deal with the incident & Event processing timeout

How to avoid ANR

ANR The key to

It's processing timeout , So it should be avoided in UI Threads ,BroadcastReceiver also service In the main thread , Dealing with complex logic and computation

And to work thread operation .

1) To avoid the activity Time consuming operation inside ,oncreate & onresume

2) To avoid the onReceiver Too many operations inside

3) To avoid the Intent Receiver There's a Activity, Because it will create a new picture , And snatch the focus from the program that the current user is running .

4) Use as much as possible handler To deal with it UI thread & workthread Interaction .

How to solve ANR

First position ANR the log:

04-01 13:12:11.572 I/InputDispatcher( 220): Application is not responding:Window{}. 5009.8ms since event, 5009.5ms since waitstarted
CPUusage from 4361ms to 699ms ago ----CPU stay ANR Usage before occurrence
04-0113:12:15.872 E/ActivityManager( 220): 100%TOTAL: 4.8% user + 7.6% kernel + 87% iowait
04-0113:12:15.872 E/ActivityManager( 220): CPUusage from 3697ms to 4223ms later:-- ANR after CPU Usage of

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

from log It can be seen that ,cpu Doing a lot of io operation .

So you can see io Where to operate .

Of course , May also be cpu Low occupancy , That's it The main thread is block Live in the .

6.Android How to communicate between threads

1) Shared variables ( Memory )

2) The Conduit

3)handle Mechanism


7.Devik process ,linux process , The difference between threads

Dalvik process .

every last android app They all take up one dvm virtual machine , Running on the linux In the system .

therefore dalvik The process and linux Process can be understood as a concept .

8. Describe the android System architecture

From childhood up is :

linux kernel,lib dalvik vm ,application framework, app How the application limits memory ? How should we use memory properly ?

activitymanager.getMemoryClass() Get memory limit .

About using memory properly , In fact, it is to avoid OOM & Memory leaks have been described in .

10. sketch android What are the application structures

1)main code

  1. unit test



mipmap It's a very early technology , Which translates as Texture mapping technology .

google It is recommended to put only the startup picture in .




Considering the length of the article , I have made these questions and answers, as well as the questions I have encountered in my interview for many years and some interview materials PDF file

Click here to get Android Summary of interview data

Technique .**

google It is recommended to put only the startup picture in .