How the AppMetrica library works

The AppMetrica library consists of two parts: the client and the service. You should take their features into account during initialization:
Client part

Pre-validates data and transmits it to the service part.

An instance of the client part is created for each process in the application.

Service part

Responsible for storing data and sending it to the server.

The service runs in a separate process. Therefore:
  • AppMetrica has a minimal effect on performance and the amount of memory consumed.
  • AppMetrica does not depend on the stability of the application. This allows you to save data and send it to the server in case of crashes and unstable operation of the application.

Recommendations on initialization

  • If the application has multiple processes, initialize the library with the same configuration for each process. Otherwise, the configuration may depend on which of the processes starts first.
    Note. You can use reporters for sending data. They can be initialized with different configurations. For more information, see Sending statistics to an additional API key.
  • Initialize the AppMetrica library in the Application.onCreate() method. This way the library will be initialized in each process.
    Attention. The code in the Application.onCreate() method runs for all processes. If you encounter an initialization error after integrating a third-party library (such as Firebase Cloud Messaging), make sure that the third-party library is initialized only in the main process. For more information, see Error descriptions.
  • Keep in mind that the ContentProvider instance is created before the Application instance. If you initialize the library in the Application.onCreate() method, you can't send data from the ContentProvider.onCreate() method.
  • Don't add code to the Application.onCreate() method that should not be executed more than once. Run this code when creating other components, or run it in a separate Service.
  • Avoid long-term operations in the Application.onCreate() method and do not initialize other libraries in it. The execution time of this method directly affects the opening speed of the first Activity, Service, or Receiver.