How to execute background task when Android app is closed / set to background?

The following code will help you to post your contents when your app is closed or in the background: import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.widget.Toast; public class SendDataService extends Service { private final LocalBinder mBinder = new LocalBinder(); protected Handler handler; protected Toast mToast; public class LocalBinder extends Binder … Read more

Need code example on how to run an Android service forever in the background even when device sleeping, like Whatsapp?

NOTE: NOW THIS ANSWER IS ONLY VALID FOR ANDROID 7 AND BELOW. SINCE ANDROID 8 GOOGLE HAS CHANGED HOW BACKGROUND TASKS ARE HANDLED Since I posted this question, I have implemented two different approaches to this solution into multiple apps. APPROACH 1 This extract is from an app where I use push notifications, which need … Read more

On Android, what’s the difference between running processes and cached background processes?

So, what are “cached background processes”? Since you are asking for a technical interpretation of something listed in a device UI, the definition may vary by device, if device manufacturers elected to tinker with the Settings app. That being said, “cached background processes” usually refers to processes that do not have a foreground activity and … Read more

iOS: Keep application running in background

Yes, no need to jailbreak. Check out the “Implementing long-running background tasks” section of this doc from Apple. From Apple’s doc: Declaring Your App’s Supported Background Tasks Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist … Read more

Run a shell script and immediately background it, however keep the ability to inspect its output

To ‘background’ a process when you start it Simply add an ampersand (&) after the command. If the program writes to standard out, it will still write to your console / terminal. To foreground the process Simply use the fg command. You can see a list of jobs in the background with jobs. For example: … Read more