Collection of Android development interview questions (including answers)

1. Start a program, you can click the icon on the main interface to enter, or you can jump from a program, what is the difference between the two?

Entering through the main interface is to set the activity to be started by default. In the activity tag of the manifest.xml file, write the following code

  <intent- filter>
      <intent android:name=“android.intent.action.MAIN”>
      <intent android:name=”android:intent.category.LAUNCHER”>
  </intent-filter>

To jump from another component to the target activity, you need to jump through the intent. specific

  Intent intent=new Intent(this,activity.class),startActivity(intent)

2. The respective characteristics and application scenarios of ArrayList and LinkedList (OnePlus)

Reference answer:

ArrayList and LinkedList are both container classes that implement the List interface and are used to store a series of object references. They can all add, delete, modify, and check elements. What are their differences, advantages and disadvantages, and application scenarios? Let's explain through source code and data structure

The general differences between ArrayList and LinkedList are as follows:

ArrayList implements a data structure based on a dynamic array, and LinkedList is based on a linked list structure.
For random access get and set methods, ArrayList is better than LinkedList because LinkedList needs to move the pointer.
For adding and deleting operations add and remove, LinkedList is more dominant, because ArrayList needs to move data.

The disadvantages of ArrayList and LinkedList are as follows:

For ArrayList and LinkedList, the cost of adding an element to the end of the list is fixed. For ArrayList, it is mainly to add an item to the internal array to point to the added element, which may occasionally cause the array to be re-allocated; for LinkedList, this overhead is uniform, and an internal Entry object is allocated.
When adding or deleting an element in the ArrayList collection, all elements behind the current list move element will be moved. The cost of adding or deleting an element in the LinkedList collection is fixed.
The LinkedList collection does not support efficient random access (RandomAccess), because it may produce quadratic item behavior.
The space waste of ArrayList is mainly reflected in the reserved capacity space at the end of the list list, while the space cost of LinkedList is reflected in the consumption of considerable space for each element of it.

The application scenarios of ArrayList and LinkedList are as follows:

ArrayList is used in the case of more queries, but fewer insertions and deletions, and LinkedList is used in the case of fewer queries and more insertions and deletions

3. RecyclerView does not understand (OnePlus)

Reference answer: Ali asked RecyclerView for 3 rounds of interviews

4. MVVM architecture, usage and principle of Databinding (OnePlus)

Reference answer:
The use of DataBinding, please click here , this article mainly introduces the principle of DataBinding

1. The role of DataBinding to implement an MVVM

2. The main technical points used by DataBinding, Java APT, observers, annotations, etc.

3. DataBinding key class

ActivityMainBindingImpl specifically implements the binding

ViewDataBinding holds the reference of activity or fragment and View. It is mainly used to traverse View once, instantiate all child Views, and store them in an array. This solves the performance problem of findviewbyid and saves us the operation of findviewbyid.

BR similar to Android R file

DataBinderMapperImpl provides a mapping from the layout file layoutid to the ViewDataBinding class object, which is mainly used to load the layout and return the corresponding ViewDataBinding object

4. How DataBinding realizes two-way binding as shown in the
figure:

DataBinding generates a ViewDataBinding subclass xxBinding at compile time, such as ActivityMainBinding. ActivityMainBinding holds View and Model and Activity/Fragment by default. There is a key method in ActivityMainBinding, excuteBinding(), where you set the value for the View and set it at the same time BindingAdapter and InverseBindingLinstener, as shown in the figure above. BindingAdapter mainly provides View's set get method and state Linstener.

If you want to refer to learn more Android interview questions, you can go directly to my GitHub address: https://github.com/733gh/Android-T3 .

5. Ways of Pushing Messages

  • Solution 1. Use Jiguang and Youmeng to push.

  • Option 2: Use XMPP protocol (Openfire + Spark + Smack)

    • Introduction : The communication protocol based on the XML protocol, formerly known as Jabber, has been standardized by the IETF International Organization for Standardization.
    • Advantages : The protocol is mature, powerful, and extensible. It is currently mainly used in many chat systems, and there is an open source Java version development example androidpn.
    • Disadvantages : The protocol is more complex, redundant (based on XML), traffic, electricity, and hardware deployment costs are high.
  • Solution 3: Use MQTT protocol

    • Introduction : Lightweight, broker-based "publish/subscribe" message transfer protocol.
    • Advantages : The protocol is concise, compact, extensible, traffic-saving, and power-saving. It has been applied to the enterprise field at present.
      Disadvantages: I am not mature enough, the implementation is more complicated, the server component rsmb is not open source, and the deployment hardware cost is high.
  • Option 4. Use HTTP round robin

    • Introduction : Regularly obtain the latest news from the HTTP server interface (Web Service API).
    • Advantages : Simple implementation, strong controllability, and low deployment hardware costs.
    • Disadvantages : Poor real-time performance.

6. Android data storage

1. Use SharedPreferences to store data.
It is a mechanism provided by Android to store some simple configuration information. It uses XML format to store data in the device. It can only be used in the same package, and cannot be used between different packages.

2. File storage Data
file storage is a more commonly used method. The method of reading/writing files in Android is exactly the same as the program that implements I/O in Java. It provides openFileInput() and openFileOutput( ) Method to read files on the device.

3. SQLite database to store data
SQLite is a standard database with Android, it supports SQL statements, it is a lightweight embedded database.

4. Use
Content Provider to store data Mainly used for data exchange between applications, so that other applications can save or read various data types of this Content Provider.

5. Network storage data
Upload (store) and download (obtain) the data information we store in the network space through the storage space provided to us on the network.

7. Broadcast registration

First write a class to inherit BroadCastReceiver

The first type: declare in the manifest file, add

  <receive android:name=".BroadCastReceiverDemo">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED">
        </intent-filter>
  </receiver>

The second type: use code to register such as:

    IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    BroadCastReceiverDemo receiver = new BroadCastReceiver();
    registerReceiver(receiver, filter);

The difference between the two registration types is:

  • The first is resident broadcast, which means that when the application is closed, if there is information broadcast, the program will be called by the system to run automatically.
  • The second is not resident broadcast, which means that broadcast follows the life cycle of the program.

8. What is the difference between memory overflow and memory leak? When will a memory leak occur?

Memory overflow :
When the memory required by the program is greater than the maximum memory allowed by the program, memory overflow will occur at this time;

Memory leak :
In some resource-consuming operations, if the memory has not been released during the operation, a memory leak will occur. For example, io and cursor are not closed.

If you want to refer to learn more Android interview questions, you can go directly to my GitHub address: https://github.com/733gh/Android-T3 .

9. How to save the activity state?

By default, the activity's state system will be automatically saved, and sometimes we need to manually call the save.

When the activity is in onPause, after onStop, the activity is in an inactive state, but the activity object still exists. When the memory is insufficient, the activity after onPause and onStop may be destroyed by the system.

When exiting the activity by returning, the activity state is not saved.

To save the activity state, you need to rewrite the onSavedInstanceState() method, and call the onSavedInstanceState method before executing onPause and onStop. OnSavedInstanceState requires a Bundle type parameter. We can save the data to the bundle and pass the actual parameter to the onSavedInstanceState method.

After the Activity is destroyed and restarted, in the onCreate method, accept the saved bundle parameters and take out the previous data.

10. What is the difference between activity, context, and application in Android?

Content and application both inherit from contextWrapper, and contextWrapper inherits from Context class.

Context :
Represents the current context object, and saves the parameters and variables in the context, which can make it easier to access some resources.
Context is usually the same as the life cycle of activity, and application represents the object of the entire application.

For some longer life cycles, do not use context, you can use application.

In activity, try to use static inner classes instead of inner classes. Internally, it exists as a member of the external class and is not independent of the activity. If there is still memory in the memory that continues to be referenced to the context, if the activity is destroyed, the context will not end.

11.Is the service executed in the main thread, and can time-consuming operations be performed in the service?

By default, the service is executed in the main thread. When the service is running in the main thread, do not perform some time-consuming operations in the service, such as network connection, file copy, etc.

12. Are Service and Activity in the same thread?

By default, service and activity are in the same thread, both in the main thread or ui thread.

If the process attribute of the service is specified in the manifest file, then the service runs in another process.

At last

The above interview questions are all the questions I asked the interviewer during the interview. There are still many Android-related interview questions I want to share with you, but due to the length of the article, I can’t show them all here, in order to be able to Effectively help everyone to answer the questions smoothly in the interview. The editor talked about some Android interview questions and summarized them into a document form. Last time I went to the [GitHub] project . If you want to learn from it, you can go to my GitHub address: https:// Check it out at github.com/733gh/Android-T3 .

If you like this article, you might as well give me a small like, leave a message in the comment area, or forward and support it~

Guess you like

Origin blog.csdn.net/dongrimaomaoyu/article/details/114990459