Android Application code stop when phone screen is locked

The issue with your app is not the process but rather the android system itself.

You need to implement something called the DOZE MODE. Such that the process/ application is not killed off when the phone is locked Google Docs On Doze Mode There is a permission you would need to implement called the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS.