Multi-process apps

Android applications can consist of one or more processes. You can choose to run your services or activities in a process other than the main one. To do this, add an android:process property inside your process or activity. Update the definition within your Android manifest file like this:

<activity
    android:name=".YourActivity"
    android:process=":YourProcessName">
</activity>
<service
    android:name=".YourService"
    android:process=":YourProcessName">
</service>

When you define your services and activities like this, you force them to run in a process other than the main process.

By default, the name of your main process is the same as your app package name. If your app package name is com.example.myapp, that will also be the name of your main process. This means that YourActivity and YourService will run in a process called com.example.myapp:YourProcessName.

The Adjust SDK does not currently support tracking for more than one process in an app. If your app uses multiple processes, you should set the main process name in your AdjustConfig object.

String appToken = "{YourAppToken}";
String environment = AdjustConfig.ENVIRONMENT_SANDBOX;  // or AdjustConfig.ENVIRONMENT_PRODUCTION

AdjustConfig config = new AdjustConfig(this, appToken, environment);
config.setProcessName("com.example.myapp");

Adjust.onCreate(config);

You can change the name of your main process. To do this, modify the android:process property of your application in the manifest file.

<application
  android:name=".YourApp"
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
  android:theme="@style/AppTheme"
  android:process=":YourMainProcessName">
</application>

If you set your main process name as above, you should also set it in the AdjustConfig object.

config.setProcessName("com.example.myapp:YourMainProcessName");

This will inform the Adjust SDK of the main process name. The SDK will not initialize in any process other than the main process. If you try to use the SDK from another process, you will see the following log message:

05-06 17:15:06.885    8743-8743/com.example.myapp:YourProcessName I/Adjust﹕ Skipping initialization in background process (com.example.myapp:YourProcessName)

If you call the SDK in multiple processes without setting the process name, you will initialize multiple instances of the SDK. This is because different processes in Android do not share the same memory space. Doing this can cause unpredictable behavior. We recommend that either:

  1. You always set your main process name for a multi-process app.
  2. You ensure that you do not use the Adjust SDK in more than one process.