Remember that “Background Launch”, “Continuous Launch” are two different tasks.
For long-term background processes, threads are not optimal with Android. However, here is the code and do it at your own peril and risk ...
Remember that the service or thread will run in the background, but our task is to execute the trigger (call again and again) to receive updates, i.e. after completing the task, we need to call the function for the next update.
Timer (periodic trigger), Alarm (time base trigger), Broadcast (event base trigger), recursion will awaken our functions.
public static boolean isRecursionEnable = true; void runInBackground() { if (!isRecursionEnable)
Using the service: if you start the service, it will start, it will complete the task and itself will stop working. after completing the task. termination can also be caused by an exception, or the user killed him manually from the settings. START_STICKY (Sticky Service) is an option provided by Android, in which the service restarts itself if the service is terminated.
Remember the question of the difference between multiprocessing and multithreading? A service is a background process (just like an action without a user interface), just like you start a thread in an action to avoid loading the main thread (activity thread), just like you need to run threads (or asynchronous tasks) in service to avoid service load.
In one expression, if you want to start a background continuation task, you need to start StickyService and start the thread in the event-based service.
Sandeep P Mar 18 '13 at 8:41 2013-03-18 08:41
source share