Process Farewell

· 313 words · 2 minute read

Process Farewell 🔗

Process Farewell facilitates simulating system-initiated process death.

It should only be used in debug builds for things like checking whether UI state is properly preserved.

Getting started 🔗

In your project’s top-level build.gradle or settings.gradle file, ensure that JitPack’s Maven repository is included:

build.gradle

allprojects {
  repositories {
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' } // add this line
  }
}

or in newer projects

settings.gradle

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' } // add this line
  }
}

Then, in your app-level build.gradle file, declare Process Farewell as a dependency:

app/build.gradle

dependencies {
  // debugImplementation because Process Farewell should only run in debug builds
  debugImplementation 'com.nikolajaksic:process-farewell:1.0.0'
}

Once application process is started, a notification is automatically displayed.

notification_single_process

If package’s default process name is not changed using android:process it is shown as ‘default’, otherwise it corresponds to an android:process attribute within AndroidManifest.xml.

Multiple processes 🔗

If you have an app that manages multiple processes, there are a few changes you’ll need to make to your code in debug build type.

src/debug/java/…/SecondaryProcess.kt

import com.nikolajaksic.processfarewell.ProcessFarewellActivity
import com.nikolajaksic.processfarewell.ProcessFarewellProvider

class SecondaryProcessFarewellActivity : ProcessFarewellActivity()
class SecondaryProcessFarewellProvider : ProcessFarewellProvider()

src/debug/AndroidManifest.xml

<manifest ... >
  ...
  <application ... >
    ...
    <activity
        android:name=".SecondaryProcessFarewellActivity"
        android:excludeFromRecents="true"
        android:exported="false"
        android:process=":[process_name_without_brackets]"
        android:taskAffinity="" />
    <provider
        android:name=".SecondaryProcessFarewellProvider"
        android:authorities="${applicationId}.[process_name_without_brackets].process-farewell"
        android:exported="false"
        android:process=":[process_name_without_brackets]" />
  </application>
</manifest>

NOTE: Repeat the above steps for each additional process.

Once application processes are started, notifications are automatically displayed.

notifications_multi_process

License 🔗

Copyright 2023 Nikola Jakšić

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.