added a way to control flushing when the app becomes inactive