สถานะการทำงาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
งานจะผ่านการเปลี่ยนแปลงหลายครั้งตลอดอายุของงานState
สถานะงานแบบครั้งเดียว
สำหรับคำของาน
one-time
งานของคุณจะเริ่มต้นในสถานะ
ENQUEUED
ในสถานะENQUEUED
งานของคุณจะมีสิทธิ์แสดงทันทีที่ตรงตามข้อกำหนดของConstraints
และเวลาหน่วงเริ่มต้น
จากนั้นจะเปลี่ยนเป็นสถานะ
RUNNING
และ
ขึ้นอยู่กับผลลัพธ์ของงาน อาจเปลี่ยนเป็น
SUCCEEDED
FAILED
หรืออาจกลับไปเป็น
ENQUEUED
หากผลลัพธ์เป็น
retry
คุณยกเลิกงานได้ทุกเมื่อในกระบวนการนี้ ซึ่งจะทำให้งานเปลี่ยนไปอยู่ในสถานะCANCELLED
รูปที่ 1 แสดงวงจรของงานแบบครั้งเดียว พร้อมเหตุการณ์ที่อาจทำให้งานเปลี่ยนไปอยู่ในสถานะอื่น

รูปที่ 1 แผนภาพสถานะสำหรับงานแบบครั้งเดียว
SUCCEEDED
, FAILED
และ CANCELLED
ทั้งหมดแสดงถึงสถานะสุดท้ายของ
งานนี้ หากผลงานของคุณอยู่ในสถานะใดสถานะหนึ่งต่อไปนี้
WorkInfo.State.isFinished()
จะแสดงค่าเป็นจริง
สถานะงานตามระยะเวลา
สถานะสำเร็จและล้มเหลวใช้ได้กับการดำเนินการแบบครั้งเดียวและการดำเนินการที่เชื่อมโยงกันเท่านั้น
สำหรับงานที่ทำเป็นระยะๆ
จะมีสถานะสุดท้ายเพียงสถานะเดียวคือ CANCELLED
เนื่องจากงานที่ต้องทำเป็นระยะๆ
ไม่มีวันสิ้นสุด หลังจากเรียกใช้แต่ละครั้ง ระบบจะกำหนดเวลาใหม่โดยไม่คำนึงถึงผลลัพธ์ รูปที่
2 แสดงแผนภาพสถานะแบบย่อสำหรับงานที่ทำเป็นระยะ

รูปที่ 2 แผนภาพสถานะสำหรับงานที่ทำเป็นระยะ
สถานะถูกบล็อก
สถานะสุดท้ายที่เรายังไม่ได้พูดถึงคือ BLOCKED
สถานะนี้ใช้กับงานที่จัดเรียงเป็นชุดหรือเป็นห่วงโซ่งาน Work
chains และแผนภาพสถานะของ Work
chains จะอธิบายไว้ในส่วนการเชื่อมโยงงาน
ขั้นตอนถัดไป
ในส่วนการจัดการงาน
คุณจะได้ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีจัดการและตรวจสอบความคืบหน้าของงาน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Work states\n\nWork goes through a series of [`State`](/reference/androidx/work/WorkInfo.State)\nchanges over its lifetime.\n\nOne-time work states\n--------------------\n\nFor a\n[`one-time`](/topic/libraries/architecture/workmanager/how-to/define-work#schedule_one-time_work)\nwork request, your work begins in an\n[`ENQUEUED`](/reference/androidx/work/WorkInfo.State#ENQUEUED) state.\n\nIn the `ENQUEUED` state, your work is eligible to run as soon as its\n[`Constraints`](/reference/androidx/work/Constraints) and initial delay timing\nrequirements are met. From there it moves to a\n[`RUNNING`](/reference/androidx/work/WorkInfo.State#RUNNING) state and then\ndepending on the outcome of the work it may move to\n[`SUCCEEDED`](/reference/androidx/work/WorkInfo.State#SUCCEEDED),\n[`FAILED`](/reference/androidx/work/WorkInfo.State#FAILED), or possibly back to\n`ENQUEUED` if the result is\n[`retry`](/reference/androidx/work/ListenableWorker.Result#retry()). At any\npoint in the process, work can be cancelled, at which point it will move to the\n[`CANCELLED`](/reference/androidx/work/WorkInfo.State#CANCELLED) state.\n\nFigure 1 illustrates the life of one-time work, with the events that may take it to another state.\n\n**Figure 1.** State diagram for one-time work.\n\n`SUCCEEDED`, `FAILED` and `CANCELLED` all represent a terminal state for this\nwork. If your work is in any of these states,\n[`WorkInfo.State.isFinished()`](/reference/androidx/work/WorkInfo.State#isFinished())\nreturns true.\n\nPeriodic work states\n--------------------\n\nSuccess and failed states apply only to one-time and\n[chained work](/topic/libraries/architecture/workmanager/how-to/chain-work).\nFor [periodic work](/topic/libraries/architecture/workmanager/how-to/define-work#schedule_periodic_work),\nthere is only one terminal state, `CANCELLED`. This is because periodic work\nnever ends. After each run, it's rescheduled, regardless of the result. Figure\n2 depicts the condensed state diagram for periodic work.\n\n**Figure 2.** State diagram for periodic work.\n\nBlocked state\n-------------\n\nThere is one final state we haven't mentioned yet, and that is `BLOCKED`. This\nstate applies to work that is orchestrated in a series, or chain of work. Work\nchains, and their state diagram, are covered in\n[Chaining work](/topic/libraries/architecture/workmanager/how-to/chain-work).\n\nNext Steps\n==========\n\nIn [Managing work](/topic/libraries/architecture/workmanager/how-to/managing-work),\nyou'll learn more about how to manage and monitor the progress of your work."]]