How the AppMetrica library works

Attention.

This is an archived version of documentation. You can find the current documentation for all platforms here.

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

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 side

It is 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 the 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.

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.