Android related knowledge

Android 6.0, 7.0, 8.0, 9.0, 10.0 new features?

[6.0] Dynamic permissions, using Builder mode to build notifications, canceling Apache HTTP client, changing Camera Camera to Camera2. It used to be first come, first served, now it is used according to priority, [7.0] permission change; [8.0] Notifications (added support for notification channels), background restriction execution, run-time permissions, permissions to install unknown applications, suspension window [9.0] Fringe adaptation, notification function changes, indoor location using Wi-Fi RTT [10.0] storage permissions, location permissions, device unique identifiers, etc

Android animation classification?

Frame Animation: Frame by Frame Animation, which plays pre-made images in sequence, similar to a movie.

Tween Animation: Animation effects are generated by continuously transforming images of objects in the scene (pan (0,0) ->(100,100), zooming and rotating).

Property Animation: supports animating objects. (0,0) -> (100,100)

Transition Animation: It is used to animate an Activity or a View.

【题目】 how did you adapt the screen before?

【 答 案 】Android Log class basic usage

www.jianshu.com/p/c77032b3c…

【题目】 how to create an Activity?

A:

【 title 】 Introduce the activity lifecycle (have a good look)

**onCreate(Bundle savedInstanceState) : ** called when the activity is created. Set up in this method to also provide access to any previously stored state in the form of a Bundle! OnStart () : called when the activity becomes visible to the user on the screen. OnResume () : called when the activity starts interacting with the user (this method is always called when an activity is started or restarted).

OnPause () : an activity is called when it is paused or reclaims CPU and other resources. This method is used to save the state of the activity and also protects the scene. OnStop () : Called when the activity is stopped and transitioned to an invisible phase and subsequent lifecycle events. OnRestart () : called when the activity is restarted. Instead of starting a new activity, the activity remains on the stack.

OnDestroy() : called when the activity is completely removed from system memory. This method is destroyed by 2. The activity life cycle when switching between horizontal and vertical screens

【题目】 do you understand fragment? What is your understanding of it?

In simple terms, a Fragment can be understood as a control with its own life cycle. However, this control is a bit special. It has its own ability to handle input events, has its own life cycle, and must rely on activities to communicate with and host each other.

1. The main purpose is to support more dynamic and flexible UI design on large screens such as tablets. Because tablet screens are much larger than mobile screens, there is more room for composing and exchanging UI components, and when you implement such designs with fragments, you don’t need to manage complex changes to the view hierarchy.

2. Code reuse. Especially suitable for modular development, because a Fragment can be nested by multiple activities, a common business module can be reused, is a good component of modular UI.

3.Activity is used to manage fragments. The life cycle of a Fragment is attached to an Activity. The Fragment can be added by Attach and released by Detach.

4. Control. Fragments can be created and controlled as freely as normal objects, passing parameters is easier and more convenient, and there is no need to deal with system related matters. Display methods, substitutions, whole or partial changes can be made accordingly.

5.Fragments are View Controllers. They contain testable, decoupled chunks of business logic.

【题目】 have you ever customized a view? What are its steps?

Customize View three ways, combination of existing controls, inherit existing controls, inherit View

  • Custom View attributes: create attrs. XML under res/values/ with attributes from the custom View
  • Get custom properties in View constructors: Override the CustomTitleView constructor to get custom properties
  • Rewrite onMesure
  • Rewrite onDraw: Rewrite the onDraw function to draw the corresponding control based on the custom properties read

SpecMode = EXACTLY: Sets the exact value or match_parent.

SpecMode = AT_MOST: Limits the sub-layout to a maximum value or warp_content.

SpecMode = UNSPECIFIED: Indicates that the child layout is UNSPECIFIED, which is rarely used in development.

The onMesure method was rewritten mainly to solve the problem that when we used the custom control, the warp_Content was not properly scaled, but was spread out, which was not what we expected.

【 Title 】 Describe the drawing process of View

www.jianshu.com/p/63e915c6c…

Within the Attach method of the activity, a PhoneWindow is created.

Call setContentView from onCreate. SetContentView is an abstract method of Window. The real implementation class is PhoneWindow:

 @Override
    public void setContentView(int layoutResID) {
        if (mContentParent == null) {

/ / 1. Initialization
        // Create a DecorView object and an mContentParent object, and associate the mContentParent object with the DecorView
            installDecor();
        } else if(! hasFeature(FEATURE_CONTENT_TRANSITIONS)) { mContentParent.removeAllViews();// The Activity is related to transition animation
        }

/ / 2. Fill the Layout
        if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) {
            final Scene newScene = Scene.getSceneForLayout(mContentParent, layoutResID,
                    getContext());
            transitionTo(newScene);// The Activity is related to transition animation
        } else {
        // Load the layout file for the Activity setting into mContentParent
            mLayoutInflater.inflate(layoutResID, mContentParent);
        }

        // Let the DecorView's content area extend below systemUi to prevent it from being overwritten during extension to achieve full screen, immersion, etc.
        mContentParent.requestApplyInsets();

//3\. Notifies the Activity that the layout has changed
        final Callback cb = getCallback();
        if(cb ! =null && !isDestroyed()) {

        // Trigger the Activity's onContentChanged method
            cb.onContentChanged();
        }
        mContentParentExplicitlySet = true;
    }
Copy the code

There are two core methods: installDecor() and mLayOutInflater.inflate (layoutResID, mContentParent);

InstallDecor creates a DecorView object that acts as the root view for the entire application window. Then configure the different window decoration properties (style theme, etc.).

Mlayoutinflater.inflate is the XML that is parsed, recursively and depth-first, to be added layer by layer to the root view and eventually returned to the root view. The parsing part consists of two parts:

1. Parse out the View object

2. Parse the Params corresponding to the View and set them to the View.

【题目】 tell me about the problems in the process of customizing a view, and how to solve them.

A:

【题目】 how many ways does Android refresh a view?

A: the runOnUiThread;

2: handler post;

Handler sendMessage;

4: View post;

All views cannot be updated in child threads
【题目】 how to implement caching in Android, through the use of third-party libraries and custom to explain the implementation of caching technology respectively?
【 title 】Android event distribution mechanism

www.jianshu.com/p/d3758eef1… www.jianshu.com/p/38015afcd… www.jianshu.com/p/555ffeb64…

View event distribution is essentially the process of MotionEvent distribution. When a MotionEvent occurs, the system passes the click event to a specific View

Click the event delivery order: Activity (Window) →ViewGroup→ View

The event distribution process is accomplished in three ways:

  • DispatchTouchEvent: Used for event distribution. This method must be called if the event can be passed to the current View, and the return result is affected by the current View’s onTouchEvent and the lower View’s dispatchTouchEvent methods, indicating whether the current event is consumed
  • OnInterceptTouchEvent: Called inside the above method to intercept the event. This method is only available in viewgroups, not views (excluding viewgroups). Once intercepted, onTouchEvent of the ViewGroup is executed and the event is processed in the ViewGroup rather than subsequently distributed to the View. It is called only once and returns a result indicating whether the current event is intercepted
  • OnTouchEvent: Called in the dispatchTouchEvent method to handle the click event and return a result indicating whether the current event is consumed
【题目】 what is the event distribution mechanism of Android view and viewGroup?
【题目】 what is the internal implementation of Handler?

Handler handles in-application communication and management. Contains handler, Looper, Message, MessageQueue, and Thread

【 title 】Android Handler mechanism principle analysis

www.jianshu.com/p/9b6f67c25…

When the main thread is created, the static method main() in the **ActiityThread class is automatically executed, and the looper.PrepareMainLooper () method is called inside the main() method to create a Looper object and a MessageQueue object for the main thread. The looper.loop ()** message loop method is then called to fetch the message

Next (), dispatchMessage(Message MSG) to the corresponding handler; 支那

Add the Message to the Message queue. Before adding the Message, set the target property of the Message object to the current handler object. Fetch the Message from the Message queue in looper.loop ().

How many handlers are there in a thread?

Multiple; Since a Handler can be new in an Activity or new in a Service, and an Activity is all running in the main thread, this proves that you can have multiple handlers in the main thread.

【题目】 the main thread Looper has been checking messages for a long time.

Android is event-driven, and common touch and Activity lifecycles are controlled by looper.loop (). If the loop stops, the entire application stops.

If there is no looper loop in the main thread, the main thread will exit as soon as it finishes running. So can we still run the APP? Obviously, that’s not possible, Looper is basically doing a message loop, and then it’s handled by a Handler, and once you exit the message loop, your APP exits.

How many loopers are there in a thread? How to guarantee?

There’s only one Looper; There is a ThreadLocal class that contains a ThreadLocalMap. Since a thread is bound to a ThreadLocalMap, if the Map contains a key-value pair with the sThreadLocal key in the current Looper, the Looper will not be stored. Instead, an exception is thrown because sThreadLocal is globally unique.

【题目】 how ThreadLocal works

ThreadLocal is an internal data store class that allows you to store data in a specified thread that cannot be retrieved by other threads.

**ThreadLocal is a great way to solve thread-safety problems by providing a separate copy of variables for each thread. In many cases, ThreadLocal is simpler and more convenient than directly using synchronized synchronization to address thread-safety issues, and the resulting program has higher concurrency.

www.jianshu.com/p/6fc3bba12…

【题目】 why do ThreadLocalMap entries use WeakReference statements?

** A: ** in order to facilitate recycling; WeakReference is a WeakReference to the applied object userInfoLocal, which does not affect the GC behavior of userInfoLocal. If it is a strong reference, we no longer use userInfoLocal during thread execution. We set userInfoLocal to null, but userInfoLocal still has a reference in thread ThreadLocalMap, so it cannot be collected by GC (of course, You can wait until the thread is finished and the entire Map is reclaimed, but many threads run for a long time, and if they wait until the thread is finished, they will occupy memory forever. When Entry is declared as WeakReference and userInfoLocal is set to NULL, the threadLocalMap of the thread is not strong reference, and userInfoLocal can be reclaimed by GC. In subsequent operations of map, the stale entries are gradually cleared out to avoid memory leaks.

【题目】 the Handler memory leak causes the Handler memory leak.

** for Handler, if we create a non-static inner class Handler directly in AndroidStudio, the large area of Handler will be marked yellow by AS. Because every non-static inner class holds a reference to an external class, this creates a potential memory leak. If the Activity is not removed from the Handler when it is destroyed, the Handler will still hold a reference to that Activity. Then you have a memory leak.

** Solution: ** use static to decorate the Handler, so that it is a static inner class, so that it does not hold references to external classes. At this point, a WeakReference can be created in the Handler to hold the external object. As soon as the external unbinds the reference, the garbage collector reclaims the weak reference as soon as it finds it.

Why can the main thread use new Handler? What does the new Handler need to do in the child thread?

A: ** There is a main() function in ActivityThread. Java, which is the first function executed by every Android application.

Prepare initializes a Looper.

Looper.loop(), which executes the for loop, keeps calling next() and polling our MessageQueue by calling next().

If prepare() is not called, Looper is not initialized. If loop() is not called, the Looper mechanism will not scroll. Therefore, all executions must be prepared () and then loop().

Since the system already does this for us when the main thread starts, all the code in our main thread runs between the two prepare() and loop() functions.

All threads must prepare() and loop(). Prepare () and loop() must be executed on child threads if they want to perform Handler operations.

【题目】 what is the postDelay and post delay of handler

A: both can be used to send Runnable objects in child threads; The Android Post () method can update the UI directly in a non-UI thread, unlike Handelr’s Send method, which needs to be switched. The two methods differ in the timing of UI thread events. PostDelayed () is used to delay execution and POST is immediately executed.

Handler.postdelay () is implemented using a combination of MessageQueue time-ordering, MessageQueue blocking, and wake up

Have you ever used AsyncTask? What is the internal implementation of this? What are its drawbacks? How to improve?
What is ANR? What causes ANR to occur?
  • ANR can occur in four ways:
  1. Unable to respond to on-screen touch events or keyboard output for 5 seconds
  2. At the executive desk broadcastonReceive()Function for 10 seconds without completion, background for 20 seconds
  3. The foreground service is not completed within 20 seconds, and the background service is not completed within 200 seconds
  4. ContentProviderthepublishIt didn’t finish in 10 seconds
  • How to avoid:

Try to avoid time-consuming operations on the main thread. How to implement multithreading, the use of thread pool

  • How to analyze ANR:
  1. When you produce anR, it’s going to be atdata/anr/Generate a file in the directorytraces.txt
  2. LogcatIn the view
  3. Java thread calls analysis
  4. Analysis of DDMS
Binder and JNI What do you understand about them?

* * a: **Binder is an interprocess communication mechanism, using C/S architecture, Binder framework mainly involves four roles Client, Server, Service Manager and Binder driver. Client, Server and Service Manager run in user space, Binder drivers run in kernel space, Client represents the Client process, Server represents the Client process to provide various services, such as audio and video, etc. Service Manager is used to manage various system services. Binder drivers provide the ability to communicate between processes

The memory mapping involved in the Binder IPC mechanism is implemented through Mmap (), a method of memory mapping in operating systems. Memory mapping simply means mapping a memory region of user space to kernel space. After the mapping relationship is established, the modification of the memory area can be directly reflected in the kernel space. Conversely, changes made to this area in kernel space can be directly reflected in user space.

There are two startup modes for apps: cold startup and hot startup.

Cold start: When an application is started, the system creates a new process and assigns the process to the application. This startup mode is cold start.

Hot start: When you start an application, the application process is already in the background (for example, you can press the home button to return to the desktop, but the application process is still in the background and can be viewed in the task list). Therefore, the application is started from the existing process. This mode is called hot start.

www.jianshu.com/p/786c0de5a…

【 Title 】 How to structure APP development at the beginning?

【 Title 】 How are APP engineering modules divided? How do you encapsulate?

【 Title 】 How is APP optimized?

Do you know OOM? How to fix memory leaks?

【 topic 】 How to realize the communication between Activity and fragment?

How does an Activity pass data to a Fragment: Bundle

How does Fragment pass data to an Activity: using interface callbacks

【 title 】 Understand the startup process of APP?

A :(1) the starting point of startup occurs in the Launcher Activity. To start an app, it is easier to start an Activity. As we said, AMS is responsible for the start, switch and scheduling of all components, so the first step is the Launcher response to the user’s click event, and then notify AMS

(2) AMS needs to respond to the notification of the Launcher by creating a new Task to start the Activity and telling the Launcher that you can rest (Paused).

(3) Launcher gets a message from AMS telling me to “rest”, so I just hang up and tell AMS I have Paused.

(4) After AMS knows the Launcher has been suspended, it can rest assured to prepare for the start of a new Activity. First, the APP must need a new process to run, so it needs to create a new process, which requires Zygote to participate in. AMS negotiates with Zygote through sockets. If a process needs to be created, AMS forks itself and creates a thread. The new process imports the ActivityThread class, which is why every application has an ActivityThread.

(5) The process is created by calling the main method of ActivityThread, which is the entry point to the application and opens the message loop queue. This is why the main thread is bound to Looper by default.

(6) At this time, the App has not been started. Always remember that all the four components need AMS to start. Register the above application process information in AMS, and THEN AMS obtains the Activity to be started from the top of the stack and completes the App startup through a series of chain calls.

Do you know which image loading libraries? What’s the difference?

Blog.csdn.net/u010312474/…

Gilde benefits 1. Image memory can be recovered in a timely manner to reduce crashes caused by insufficient memory. The life cycle of Gilde is the same as that of Activity/Fragment. 2. The default Bitmap format is RGB_565, which reduces memory usage. 3. Glide takes up less memory than universal-image-loader. 4, the image display effect for gradual change, more smooth. Glide can decode any local video into a still picture. 6, support Gif, WebP, thumbnail

What is the internal caching mechanism of ImageLoader? How is it done?

Imageloader has two levels of cache: memory cache and local file cache (some say level 3 cache, level 3 network cache). But bloggers argue that the web should not count in the cache. Please do not spray purely personal opinion! In this post I’m going to take a look at the memory cache part with you.

Blog.csdn.net/shu_lance/a…

How is asynchronous communication implemented in Android?

Blog.csdn.net/carson_ho/a…

What third party libraries do you use in your development? Have you read their source code?
Do you know anything about radio? How does it differ from EventBus? Can it be mutually realized?

** Standard broadcast: a broadcast that is performed asynchronously. When a broadcast is sent, the broadcast receiver will receive the broadcast message at almost the same time, so there is no order at all, and it is efficient and cannot be truncated.

** Ordered broadcast: a synchronous broadcast in which a broadcast message is received by a broadcast receiver and the broadcast continues only after the logic in the broadcast receiver has been executed. There is a sequence in which the receiver with a higher priority receives the broadcast message first and can intercept the broadcast being transmitted so that subsequent receivers cannot receive the broadcast message.

** System broadcast: **Android has many built-in system level broadcasts, such as a broadcast when the phone is turned on, a broadcast when the battery changes, etc.

What is Hibernate framework?

Hibernate is an ORM framework (Object_Relative DateBase-Mapping**) that sets up a Mapping between Java objects and relational databases to directly access Java objects.

We use Hibernate framework we do not need to write a lot of tedious SQL statements, thus simplifying our development!

How are your network requests implemented?
Do you know Volley? What is the internal implementation process?

Blog.csdn.net/droyon/arti…

What is the difference between Volley and OKHttp?

www.voidcn.com/article/p-g…

What third party functions do you know? Do you know push? How does it work?

Blog.csdn.net/cyjbenyy/ar…

Activity startup mode and startActivityForResult for various startup modes

The startActivityForResult methods work: Standard and singleTop

The startActivityForResult methods are not working: singleTask and singleInstance

【 答 案 】 There are four different startup modes for an Activity

www.jianshu.com/p/7e70ee765… Blog.csdn.net/zy_jibai/ar…

  • ** Standard mode: ** Every time you start a standard mode Activity, a new instance is created, regardless of whether the Activity already has an instance. There can be multiple instances in a task stack, and each instance can belong to a different task stack. Who started the Activity? The Activity instance then runs on the same stack as the Activity that started it.

  • ** Stack Top reuse mode (singleTop) : ** In this mode, if the newly started Activity is already at the top of the stack, the Activity is not recreated. Instead, the onNewIntent method is called again. Neither onCreate nor onStart is called by the system. If the new Activity instance already exists but is not at the top of the stack, then recreate the Activity and place it at the top.

  • SingleTask: ** This is a single-instance mode in which there is only one instance of the same Activity in a stack. If there is an instance, it will not be recreated, regardless of whether it is at the top of the stack.

  • ** singleInstance: ** this is an enhanced singleTask mode. In addition to all the features of singleTask mode, it also enhances that this mode can only be placed in a singleTask stack, different applications to open the Activity share the same common Activity. It will run in its own separate, independent task stack, and there is only one instance of it in the task stack.

The difference between context and ApplicationContext

First, activity.this and getApplicationContext() do not return the same object. One is an instance of the current Activity, and the other is an instance of the project’s Application. Enclosing getApplicationContext () is the application of the Context of its life cycle along with the existence of the application; Activity.this takes the Context of the current Activity, and its life cycle can only exist in the current Activity. The two life cycles are different. The getApplicationContext() lifecycle is the entire application, which is destroyed when the application is destroyed; Activity. This context belongs to the current Activity and is destroyed when the current Activity is destroyed.

What is the difference between onPause and onStop?
【 title 】 Performance comparison of five Android layouts?
What are the four components of Android? What do you understand about each of them?
【 title 】Android’s four components, six layout, five storage

Blog.csdn.net/shenggaofei… Blog.csdn.net/xiankog/art…

【题目】 the difference between apply() and commit() in SharedPreferences data store

SharedPreference related modifications are first written to memory and then asynchronously written to disk using apply.

The commit method writes directly to disk. If applied frequently, apply performs better than COMMIT, and apply writes the last changes to disk. However, if you want to immediately retrieve the results of a storage operation and do other operations accordingly, use COMMIT.

【题目】 how does Android signature work?
What contents does the decompressed folder contain?
【 答 案 】OkHttp

Juejin. Cn/post / 684490… www.jianshu.com/p/eca3d9371…

【 答 案 】 What is your understanding of Service? What’s the difference in how it starts?

Are services executed in the main thread and can time-consuming operations be performed in the service? By default, services and activities run in the main thread of the current app process if there is no process running in the service. The service cannot perform time-consuming operations (network requests, copying databases, large files). You can configure the process of the service in the manifest file to execute it in another process.

How to bind an Activity to a Service, and how to start its own Service in an Activity? The Activity by bindService (Intent service, ServiceConnection conn, int flags) bind with the service, When the binding is complete, the ServiceService passes the proxy object to Conn via callback, and we get the Service proxy object provided by the Service. You can start a Service in an Activity using the startService and bindService methods. The bindService() method is usually required if you want to obtain Service objects, such as music players, third-party payments, etc. You can use the startService() method if you just want to start a background task.

【 title 】 MVC MVP MVVM three architectural patterns

MVC: A pattern of separation of business logic, data, and interface. In simple terms, the controller manipulates the data in the Model layer and returns it to the View for display.

An activity is not a standard controller, and as the complexity of the interface’s logical interactions increases, the activity class’s responsibilities increase and become bloated. The View and model are coupled to each other, which is not conducive to development.

MVP: Mainly presents the Presenter layer as a bridge between view and Model.

The program logic is handled in the Presenter, completely separating the View from the Model and not allowing them to communicate with each other.

MVVM: The presenter is a viewModel, just like the MVP, except that the ViewModel is bidirectionally bound to the View and the Model.

A data binding is used

【 topic 】 Design patterns

www.runoob.com/design-patt…

【题目】 the difference between observer mode, EventBus, BroadcastReciver

Blog.csdn.net/qq_34895720…

Define a one-to-many dependency between objects so that whenever an object changes state, all dependent objects are notified and updated automatically.

【 topic 】 The use of Android EventBus

www.jianshu.com/p/e7d5c7bda…

【 title 】Android APK packaging process

Blog.csdn.net/wangzhongsh…

【题目】 do you know about multi-channel packaging in Android?
【 title 】SparseArray introduction

Blog.csdn.net/ma175629564…

【 答 案 】 The difference and use of Parcelable and Serializable

Blog.csdn.net/hacker_craz…

【 title 】 Introduction to display principle of Android system

www.jianshu.com/p/a978a6250…

What is Spring Boot?

Spring Boot is a sub-project of Spring open source organization. It is a one-stop solution for Spring components. It mainly simplifies the difficulty of using Spring, saves heavy configuration, and provides various initiators for developers to get started quickly.

Why Spring Boot?

No code generation and XML configuration

What are the core configuration files for Spring Boot? What’s the difference?

The core configuration files for Spring Boot are the Application and Bootstrap configuration files.

Application configuration file This is easy to understand and is mainly used for automatic configuration of Spring Boot projects.

The bootstrap configuration file can be used in the following scenarios.

  • When you use Spring Cloud Config to configure the configuration center, you need to add the configuration properties connected to the configuration center in the bootstrap configuration file to load the configuration information of the external configuration center.
  • Properties that are fixed and cannot be overridden;
  • Some encryption/decryption scenarios;
What is the core annotation of Spring Boot? Which notes are it mainly composed of?

The annotation above the Boot class is @SpringBootApplication, which is the core annotation of SpringBoot. The main combination contains the following three annotations:

@springBootConfiguration: The @Configuration annotation is combined to realize the function of the Configuration file.

@enableAutoConfiguration: Enable the automatic configuration function or disable an automatic configuration option, such as data source automatic configuration: @ SpringBootApplication (exclude = {DataSourceAutoConfiguration. Class}).

@ComponentScan: Spring component scanning.

What do you think of the Starters in Spring Boot?

“Starters” is a set of “Starters” that can be integrated into your app, giving you a one-stop way to integrate Spring and other technologies without having to dig around for sample code and dependencies. If you want to use Spring JPA to access a database, simply add the spring-boot-starter-data-jPA initiator dependency.

The interview summary website: www.cnblogs.com/marsitman/p… www.jianshu.com/p/c93965357… Blog.csdn.net/xiaohulunb?… How2j. Cn/k/j2se – inte… www.jianshu.com/p/cfac5c131… www.jianshu.com/p/d256d8e3d… www.jianshu.com/p/5eb9ab39d…

Brush website: cattle from the sword refers to the offer, listen to online brush 3 times, then a little more, feel time consumption in the two times goes into www.nowcoder.com/ta/coding-i… Leetcode HOT100: leetcode-cn.com/problemset/… Basic knowledge of web site: Java foundation course: www.feiyangedu.com/referer/ag2… Common Linux commands: www.cnblogs.com/yjd_hycf_sp…