In android, when resources are low, the device may kill an application (usually in the background) to re-allocate those resources to the app the user is interacting with at the moment.

This is a different process than force-stopping or killing the application, both of which are easy to simulate with ADB commands:

adb shell am kill com.yourpackage
adb shell am force-stop com.yourpackage

The above commands will completely destroy the activity and if opened again (by tapping the app icon, or even from the Recents list), the application will start again at it’s launcher Activity.

This makes it difficult to develop and test restoration behavior. It is possible however to programmatically force the system to reclaim the app, exactly as it would when doing so organically to support another app in the foreground. The ActivityManager class has a method: killBackgroundProcesses that does just this. However, you need both an explicit permission:

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

While this may work when foregrounded, the process is more realistically simulated if it occurs in the background. One way to do this is to start a new Thread in the onPause of an Activity that calls the method after some arbitrary delay. For example:

final ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
new Thread(() -> {
  try {
  } catch (InterruptedException e) {