Search code examples
androidmemory-managementactivity-lifecycleandroid-memory

Android: make the system to kill the app's process instead of destroying paused/stopped activities


Is it possible to force Android to kill the entire app's process instead of destroying activities which run in the background? Because, I don't want the system to recreate the destroyed activities since the app won't work correctly in this case. Thus, I think it's more "user-friendly" to kill the entire process so the user will simply start the app again and everything works as is should. The solution should not affect normal "resuming" (when the activity is still running in background)..


Solution

  • Is it possible to force Android to kill the entire app's process instead of destroying activities which run in the background?

    Yes, use android.os.Process.killProcess(android.os.Process.myPid()); For more info refer Process

    myPid () - Returns the identifier of the process, which can be used with killProcess(int)