Does Android create new process when app crashes?

Viewed 116

I’m interested in what actually happens when Android app crashes. Imagine such a situation - we have an app that doesn’t use any custom exception handlers, just stock Android behavior. Then for what ever reason the app crashes and Android tries to either recreate top most activity(if it has the valid state) or throw it away and switch to some parent activity , but where this actually happens ? Is this happens on the very same process the app was running before the crash on Android setups compleatly new process for this reason ? Thanks !

1 Answers

Application process will not be recreated if activity crashes. Process can be stopped if there is something unexpected happened at application level. Its very rare. Application process are maintain by OS. If you want to stop process on activity crash then you have to programaticall tell OS to kill underline process

android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);

All the processes are managed by OS. OS can terminate process(in case low memory) and save instance of process in cache. So when next time application starts it uses saved state from cache togive user seamless experience If you see application callbacks there is no callback like Activity callback onStop or onDestroy. There is callbacks like onLowMemory, onTrimMemory and onTerminate

For more details visit https://developer.android.com/guide/components/activities/process-lifecycle and https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner

Related