I have an application that uses AsyncTasks to make REST calls to a server. Whenever the AsyncTask is finished, it either: shows an error dialog/calls the next activity (if the application is in foreground) or does nothing (application is in background).
I do this to avoid having an activity poping out after the application is sent to background.
I've seen some implementations:
- check android application is in foreground or not?
- Determining the current foreground application from a background task or service
Currently i'm using another, even simpler:
- onResume of each activity I set a global variable as FOREGROUND
- onPause of each activity I set a global variable as BACKGROUND
Which would you recommend?
PS I am aware of the best practice of REST calls as described in this video https://www.youtube.com/watch?v=xHXn3Kg2IQE&list=PL73AA672847DC7B35 and in my specific case this approach seems more appropriate.