Added a flag for stopping the service during processing if app is closed