Why is Android Worker finishing successfully and calling onStopped()

后端 未结 3 918
情深已故
情深已故 2021-01-13 07:55

My current Android app employs androidx.work:work-runtime:2.2.0-rc01

My Worker code resembles this:-

class SyncWorker(context: Context,          


        
3条回答
  •  一整个雨季
    2021-01-13 08:21

    Its working as expected as per the documentation which for "Worker" class says:

    Once you return from this * method, the Worker is considered to have finished what its doing and will be destroyed. If * you need to do your work asynchronously on a thread of your own choice

    And also for onStopped() method of ListenableWorker class.

     /**
         * This method is invoked when this Worker has been told to stop.  This could happen due
         * to an explicit cancellation signal by the user, or because the system has decided to preempt
         * the task.  In these cases, the results of the work will be ignored by WorkManager.  All
         * processing in this method should be lightweight - there are no contractual guarantees about
         * which thread will invoke this call, so this should not be a long-running or blocking
         * operation.
         */
    

提交回复
热议问题