My app is synced with data that is received using an asynctask. When data is received I update a listview and generate a notification. It works great but in case the app is in pause mode, I want only to generate a notification. I want it to continue executing this asynctask even after onPause (if the user switched to another app or pressed the home key).
I read a lot of posts here about how to repeat an action but never saw a reference to what happen when/if the app goes into pause mode.
Why not start a service that runs a background thread? The service will continue running even if you are not using your app. When the onStop() of your main activity is called, start the service. The thread in the service sleeps and every so often connects to the server and checks for updates.
In the onCreate() of the service, start the thread. In the onStartCommand() (which is called if the service already exists) of the service, check if the thread is alive. If not, start the thread.
Guide for creating services: https://developer.android.com/guide/components/services.html