Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Java Service and Timer/Thread Sleep
    primarykey
    data
    text
    <p>Basically, what I need to code is simple, but as I'm a beginner, I am still confused about Service, IntentService, creating a new Thread separate from the main Activity/UI thread, etc. I'll explain the Task first and then, how I think this might be best achieved.</p> <p><strong>Task</strong></p> <p>The Main Activity/UI has two buttons, Start and Stop. The App should make a cycle of two tasks, TaskA and TaskB. When Start is pressed, the cycle is executed. The cycle has these steps inside-</p> <ol> <li>Update Status on the Main Activity's UI: "TaskA execution in 60 seconds"</li> <li>Wait 60 seconds</li> <li>Update Status ... : "TaskA Executing"</li> <li>Execute TaskA</li> <li>Update Status ... : "TaskB execution in 120 second"</li> <li>Wait 120 seconds</li> <li>Update Status ... : "TaskB Executing"</li> <li>Execute TaskB</li> </ol> <p>On completion, the cycle repeats. This cycle must continue until the user presses Stop. This cycle must not stop, be interrupted or be destroyed if the Main Activity/UI is onPause, onStop, or onDestroy. The Main Activity/UI should be completely separate from the cycle thread.</p> <p>Stop button: Stops the execution of all the Steps inside the cycle, regardless of which step it is. Cancel all scheduled tasks and Stop the Service. The state the App should be at now must be as if the App is being started the first time (the same state it was before Start was pressed).</p> <p><strong>Problem</strong></p> <p>I am unsure the full functions of Service and IntentService. I know Service can perform multi-threading whereas IntentService performs a task queue and performs them one by one.</p> <p><strong>Potential Solution</strong></p> <p>My cycle above needs to perform those 8 steps in that exact order so IntentService would be the ideal solution.</p> <p>But my question is: can I create an IntentService that is completely independent from the Main Activity/UI thread so that it does not rely on the Main Activity's lifecycle or thread?</p> <p>If not, what would be the ideal alternative to achieve this?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload