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

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 for 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.

    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. As a result, the library will be initialized within each process.

    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.

Learn more

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.

Contact support