How can I make API call before terminating the app