Many friends have gone through many interviews at one time or another. Some of them got the offer they wanted, and some of them were rejected. So today I sorted out a list of questions often asked in interviews, hoping to help more people.

This article explains:

  • Why do we leave
  • Interview questions must be asked in an interview
  • How to choose a company

1. Why do we choose to leave

  • Wages can’t keep up with consumption
  • I can’t find my sense of belonging and achievement at work. I feel like I’m in prison
  • There is no room for development in the company (BEFORE, I have an article about choosing a company that pays attention to salary and personal salary, you can refer to the headline of changing from BAT company with flat salary, is it worthwhile?)

2.25K+Android engineers must ask interview questions

1.APK installation involves the following directories:

  • System /app: built-in system applications that cannot be deleted
  • Data /app: indicates the directory where the user program is installed and has the deletion permission. Copy the APK files to this directory when you install
  • Data /data: stores application data
  • Data/Dalvik-cache: Install the dex file in APK to the dalvik-cache directory

Copy the APK installation package to the data/app directory, decompress and scan the installation package, save the dex file (Dalvik bytecode) to the Dalvik-cache directory, and create the corresponding application data directory in the data/data directory

2. Invalidate() and postInvalidate(

Invalidate () is used to refresh the View and must work in the UI thread. For example, when modifying the display of a view, invalidate() is called to see the redrawn interface. PostInvalidate () is called in the worker thread.

3. Difference between Parcelable and Serializable

Parcelable has better performance than Serializable and less memory overhead. Therefore, it is recommended to use Parcelable when transferring data between memory, such as transferring data between activities, while Serializable can store data persistently for convenience. Therefore, Serializable should be selected when data needs to be saved or transmitted over the network. Since Parcelable may vary between android versions, it is not recommended to use Parcelable for data persistence.

Serializable does not save static variables. Some fields can be serialized without using the Transient keyword, and writeObject and readObject methods can be overridden to achieve customization of the serialization process.

4. Several ways to transfer data across processes in Android

  • Binder
  • Socket/LocalSocket
  • The Shared memory

5. Use scenarios of anonymous shared memory

In The Android system, a unique Anonymous Shared Memory subsystem (Ashmem) is provided, which is implemented in the kernel space in the form of drivers. Binder interprocess communication facilitates memory sharing by assisting memory management systems to efficiently manage unused chunks of memory.

Ashmem is not like Android reinventing itself with Binder, but rather uses Linux’s TMPFS file system. TMPFS is a fast file system that can be based on RAM or SWAP, which can then be used to share memory between different processes.

The general idea and process are as follows:

  • Proc A creates A shared region using TMPFS and gets the FD (file descriptor) for that region.
  • Proc A Mmap an area of memory on A FD to the process to share data
  • Proc A somehow inverts the FD to Proc B
  • Proc B adds the same mmap region of the received FD to the process
  • Then A and B read and write in mmap to the memory of the process, which can be seen by each other

The core point is to create a shared area, and then two processes simultaneously mmap this area to the process, and then read and write it as if it were its own memory. In Proc A, open A file to get A FD, but put the open FD directly into Proc B, Proc B cannot use it directly. But files are unique, meaning that A file can be opened multiple times, each time with A FD (file descriptor), so for the same file, some transformation is required to convert the FD in Proc A to the FD in Proc B. This allows Proc B to pass fd mmap of the same shared memory file.

Application scenario: Transfer a large amount of data between processes

6. Implementation principle of ContentProvider

A ContentProvider has the following two features:

  • Encapsulation: Encapsulates data and provides a unified interface that users do not care about whether the data is requested in DB, XML, Preferences, or the web. When the project needs to change the data source, the use of our place does not need to be modified at all.
  • Provides a way to share data across processes.

The Content Provider component transfers data between applications based on an anonymous shared memory mechanism. Its main call process:

① Use the ContentResolver to find the ContentProvider corresponding to the given Uri and return the corresponding BinderProxy

  • If the Provider has not been used by the calling process:

    • Use the ServiceManager to find the Activity Service and obtain the BinderProxy corresponding to ActivityManagerService
    • Call the transcat method of BinderProxy and send GET_CONTENT_PROVIDER_TRANSACTION to get the BinderProxy of the corresponding ContentProvider.
  • If the Provider is already used by the calling process, the calling process keeps the HashMap that used the Provider. You can query the table directly.

Call BinderProxy query()

7. How to use ContentProvider for batch operations?

We usually use “transactions” for bulk manipulation of data, but how does ContentProvider perform bulk manipulation? Create an array of ContentProviderOperation objects, and then use the ContentResolver applyBatch () will be assigned to the content provider. You need to pass authorization for the content provider to this method, not a specific content URI. This makes each ContentProviderOperation object in the array applicable to other tables. Call ContentResolver. ApplyBatch () will return the result array.

We can also observe the data through ContentObserver:

  • To create our particular ContentObserver derived class, we must override the onChange() method to handle the function implementation after the callback
  • Using context. GetContentResolover () to obtain ContentResolove object, then call registerContentObserver () method to observer registered trademark, Register an instance of a ContentObserver derived class for the specified Uri and call back the instance object to handle it when the given Uri changes.
  • Life cycle as a result of the ContentObserver synchronization in the Activity and Service, etc., therefore, when not needed, need to manually call unregisterContentObserver () to cancel the registration.

8. What are the problems if I do not unregister after broadcasting registration? (Memory leak)

You can register an BroadcastReceiver either dynamically during the Activity startup process with code or statically with the < Receiver > tag in the Androidmanifest.xml file.

  • For the first method, we need to make it a good habit to use the unregisterReceiver method to unregister a registered BroadcastReceiver when an Activity is stopped or destroyed.
  • For those registered with the < Receiver > tag, instances of the object are destroyed at any time after onReceive is called.

9. Difference between Property Animation and Tween Animation

10. Can time-consuming operations be performed in BrocastReceive?

11.Android optimization tools: TraceView and Systrace

12. The difference between Dalvik and ART?

Android Dynamic Permissions?

14. How can ViewPager determine left/right sliding?

Implement OnPageChangeListener and rewrite the onPageScrolled method, judging by the parameters.

15. With RecyclerView ListView

16. Describe the startup process of Android phone and App? Android phone startup process

When we boot up, we start the Linux kernel first. In the Linux kernel, init is started first. This process reads the configuration file system\core\ RootDIR \init.rc, which contains Zygote, the first process in the Android system.

Start Zygote process –> Create AppRuntime (Android operating environment) –> Start VIRTUAL machine –> Register JNI method in virtual machine –> initialize Socket used for process communication (for receiving AMS requests) –> Start system service process –> Initialize common information like time zone, keyboard layout, etc. –> Start Binder thread pool –> initialize system services (including PMS, AMS, etc.) –> start Launcher

App Startup Process

image.png

  • The application starts when another application calls startActivity. Request AMS to start the Activity through the proxy.
  • AMS creates the process and enters the Main entry of ActivityThread. At the main entrance, the main thread is initialized and looped. Main thread initialization, mainly instantiation of ActivityThread and ApplicationThread, and creation of MainLooper. The ActivityThread and ApplicationThread instances are used to communicate with the AMS process.
  • The application process passes the instantiated ApplicationThread, Binder to AMS so that AMS can access the application process through a proxy.
  • AMS, through the proxy, requests that the Activity be started. ApplicationThread tells the main thread to execute the request. The ActivityThread then starts the Activity.
  • The start of an Activity includes instantiation of an Activity, Application instantiation, and the start process of an Activity: Create, Start, resume.

You can see that the entry Activity actually precedes the Application instantiation, just a process like onCreate, which precedes the Activity’s process. In addition, scheduleLaunchActivity is required. In ApplicationThreaad, scheduleXXXActivity is used by AMS to manage the Activity lifecycle. ApplicationThread is used by Binder threads. It sends a message to the main thread, and the Handler of the ActivityThread calls the corresponding handleXXXActivity method, which then executes the performXXXActivity method, and finally calls the Activity’s onXXX method

17. Differences between the Asset directory and the RES directory

Does Application call onCreate() multiple times in multiple processes? When using multiple processes, such as the following Service configuration:

<service
    android:name=".MyService"
    android:enabled="true"
    android:exported="false"
    android:process=":remote" />
Copy the code

The android: Process property appends this name to the standard process name your package is running as the new process name.

This configuration calls onCreate() twice

19. What is the difference between FragmentPagerAdapter and FragmentStateAdapter?

20.SurfaceView && View && GLSurfaceView

For more answers, please refer to the end of the article

How to choose your favorite company

Multiple offers, how to choose? The factory elects big, the factory small elects the company to have money, almost elects to work overtime little, works overtime all much, elects money much.

For details on how to judge whether a company is good or bad, you can refer to my previous article: Is it worthwhile to change headlines from a company like BAT with flat salary? How to judge the quality of a software company and job-hopping, how to find a reliable company?

As long as the technology is in hand, there is food everywhere, and don’t quit naked, okay