Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WorkManager(Updated)

takahirom
June 07, 2018
2.9k

 WorkManager(Updated)

takahirom

June 07, 2018
Tweet

Transcript

  1. 荈ⴓחאְג ˖ UBLBIJSPN !OFX@SVOOBCMF  ˖ 劤せכ嬁「䃨峔 ׭׿ׄױ׋ַמ׹  ˖

    "OESPJEָ㥨ֹדׅկ ˖ "CFNB57ך"OESPJE،فٔ׾⡲׏גְתׅկ ˖ ջ(PPHMF*0ًٌ 끅ְ׋הֿ׹ռהְֲ 2JJUB׾剅ֹת׃׋
  2. ˖ ة؎ىָؚٝ䖓חז׏ג׮״ֻծ⹛⡲ׅ׷ֿהָ⥂鏾׃׋ְ㜥 さ׋ֻׁ׿ך鍑寸倯岀ָ֮׷կ ˖ +PC4DIFEVMFS 'JSFCBTF+PC%JTQBUDIFS "MBSN.BOBHFS  #SPBEDBTU3FDFJWFST ˖

    ⟃♴ך״ֲז鍑寸ٗآحؙ׾荈ⴓד剅ְגծ׋ֻׁ׿ךֿה׾ 罋䣁׃זָ׵׋ֻׁ׿ך"1*ךㄎן⳿׃׾剅ֻ䗳銲ָ֮׷կ %FGFSSBCMFHVBSBOUFFEFYFDVUJPO ך⡦ָ㉏겗ַ
  3. ˖ ة؎ىָؚٝ䖓חז׏ג׮״ֻծ⹛⡲ׅ׷ֿהָ⥂鏾׃׋ְ㜥 さ׋ֻׁ׿ך鍑寸倯岀ָ֮׷կ ˖ +PC4DIFEVMFS 'JSFCBTF+PC%JTQBUDIFS "MBSN.BOBHFS  #SPBEDBTU3FDFJWFST ˖

    ⟃♴ך״ֲז鍑寸ٗآحؙ׾荈ⴓד剅ְגծ׋ֻׁ׿ךֿה׾ 罋䣁׃זָ׵׋ֻׁ׿ך"1*ךㄎן⳿׃׾剅ֻ䗳銲ָ֮׷կ %FGFSSBCMFHVBSBOUFFEFYFDVUJPO ך⡦ָ㉏겗ַ
  4. ˖ ة؎ىָؚٝ䖓חז׏ג׮״ֻծ⹛⡲ׅ׷ֿהָ⥂鏾׃׋ְ㜥 さ׋ֻׁ׿ך鍑寸倯岀ָ֮׷կ ˖ +PC4DIFEVMFS 'JSFCBTF+PC%JTQBUDIFS "MBSN.BOBHFS  #SPBEDBTU3FDFJWFST ˖

    ⟃♴ך״ֲז鍑寸ٗآحؙ׾荈ⴓד剅ְגծ׋ֻׁ׿ךֿה׾ 罋䣁׃זָ׵׋ֻׁ׿ך"1*ךㄎן⳿׃׾剅ֻ䗳銲ָ֮׷կ %FGFSSBCMFHVBSBOUFFEFYFDVUJPO ך⡦ָ㉏겗ַ ֿ׸ח8PSL.BOBHFSָ㼎䘔ׅ׷
  5. ⢽ִלו׿זةأؙ ˖ ӧخ؎٦ز ˖ ӧًر؍،ؿ؋؎ٕך؟٦غ٦פך،حفٗ٦س ˖ ӧر٦ةךػ٦أהر٦ةك٦أפך⥂㶷 ˖ –ػٖحزؕٓ٦׾䬄⳿׃ג*NBHF7JFX׾،حف ر٦ز

    ˖ –ر٦ة׾ػ٦أ׃ג7JFXך،حفر٦ز ˖ –铬ꆃךزٓٝؠؙءّٝ׾㹋遤 ⳿ⰩIUUQTZPVUVCF*S,P#'-X5/ ^ ˖ 5ISFBE1PPM ˖ 3Y+BWB ˖ ,PUMJO $PSPVUJOF
 ׾⢪ֲ
  6. ⢽ִלו׿זةأؙ ˖ ӧخ؎٦ز ˖ ӧًر؍،ؿ؋؎ٕך؟٦غ٦פך،حفٗ٦س ˖ ӧر٦ةךػ٦أהر٦ةك٦أפך⥂㶷 ˖ –ػٖحزؕٓ٦׾䬄⳿׃ג*NBHF7JFX׾،حف ر٦ز

    ˖ –ر٦ة׾ػ٦أ׃ג7JFXך،حفر٦ز ˖ –铬ꆃךزٓٝؠؙءّٝ׾㹋遤 ⳿ⰩIUUQTZPVUVCF*S,P#'-X5/ ^ ˖ 5ISFBE1PPM ˖ 3Y+BWB ˖ ,PUMJO $PSPVUJOF
 ׾⢪ֲ ˖ 'PSFHSPVOE 4FSWJDF׾⢪ֲ
  7. 8PSLFS׾⢪׏ג׫׷ const val KEY = "key" class AddHelloWorker : Worker()

    { override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } }
  8. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } 8PSLFS׾竰䪫׃ג㹋鄲
  9. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } EP8PSL ׾㹋鄲׃ג 㹋ꥷחֿך8PSLד װ׷ֿה׾剅ֻ
  10. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } EP8PSL ך⚥כ CBDLHSPVOEUISFBEד㹋遤ׁ׸׷
  11. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } 䗳銲ח䘔ׄג䒷侧הז׷JOQVU%BUB׾《׸׷ JOQVU%BUBכBOESPJEYXPSL%BUBؙٓأ 䖓鶢
  12. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } ➙㔐כ俑㶵⴨׾穠さׅ׷
  13. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } NBQ׾XPSLSVOUJNFLUYךUP8PSL%BUB ד BOESPJEYXPSL%BUBؙٓأח㢌䳔
  14. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } PVUQVU%BUBח➿Ⰵׅ׷
  15. const val KEY = "key" class AddHelloWorker : Worker() {

    override fun doWork(): WorkerResult { val inputString = inputData.getString(KEY, "") val outputString = "Hello, $inputString" outputData = mapOf(KEY to outputString).toWorkData() return WorkerResult.SUCCESS } } 8PSL3FTVMU׾鵤ׅ 46$$&44 '"*-63& 3&53: 3&53:׾鵤ׇל׮ֲ♧䏝㹋遤דֹ׷
  16. 8PSLFS׾⢪׏ג׫׷ val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest)

    // workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } }
  17. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } } 8PSL3FRVFTU׾⡲䧭
  18. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } TFU*OQVU%BUBדر٦ة׾床ׅ
  19. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } FORVFVF ד㹋遤
  20. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } 8PSL.BOBHFSHFU4UBUVT#Z*Eד -JWF%BUB8PSL4UBUVTָ《䖤דֹ׷
  21. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } } JEכ8PSL3FRVFTUַ׵《䖤דֹ׷կ
  22. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } } }) 8PSL4UBUVT4UBUFד朐䡾׾鋅׷ #-0$,&% $"/$&--&% &/26&6&%  '"*-&% 36//*/( 46$$&&%&%ָ֮׷
  23. val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance().enqueue(workRequest) //

    workΛ؂ࢹ WorkManager.getInstance() .getStatusById(workRequest.id) .observe(this, Observer<WorkStatus?> { workStatus -> workStatus ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { val outputData: Data = workStatus.outputData val output = outputData.getString(KEY, "default") toast(output) } else -> { } } }) XPSL4UBUVTַ׵PVUQVU׃׋ر٦ةךؙٓأח ،ؙإأדֹ׷
  24. 8PSL.BOBHFSך堣腉稱➜ ˖ 8PSLך⣛㶷ؚٓؿָ⡲׸׷ ˖ UIFO ד8PSL׾籬־׵׸׷ ˖ 3Y+BWBך[JQ׫׋ְזֿהָדֹ׷ ˖ *OQVU.FSHFS׾⢪ֲ

    ˖ 8PSLח勴⟝׾אֽ׵׸׷ ˖ -JWF%BUBד➙ך朐䡾ָ鋅׵׸׷ ˖ 8PSLחةؚ׾אֽג穾׶鴥׫זוָדֹ׷ ˖ ثؑ؎ٝꟚ㨣儗חِص٦ؙזせ⵸׾אֽג穾׶鴥׫װծ
 ずׄせ⵸ָ崧׸׋הֹךⵖ䖴ָדֹ׷
  25. UIFO ד8PSL׾籬־׵׸׷ ˖ ⱖ溪ךؿ؍ٕة٦׾ַֽ׋䖓،حفٗ٦س׃׋ְהֹזוחⵃ欽ׅ׷ ˖ ➙㔐כ8PSME)FMMP 8PSME)&--0 803-%׾װ׏ג׫׋ WorkManager.getInstance() .beginWith(

    OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData( mapOf( KEY to "World" ).toWorkData() ) .build() ) .then(OneTimeWorkRequestBuilder<UpperCaseWorker>().build()) .enqueue()
  26. 8PSL.BOBHFSך堣腉稱➜ ˖ 8PSLך⣛㶷ؚٓؿָ⡲׸׷ ˖ UIFO  ד8PSL׾籬־׵׸׷ ˖ 3Y+BWBך[JQ׫׋ְזֿהָדֹ׷ ˖

    *OQVU.FSHFS׾⢪ֲ ˖ 8PSLח勴⟝׾אֽ׵׸׷ ˖ -JWF%BUBד➙ך朐䡾ָ鋅׵׸׷ ˖ 8PSLחةؚ׾אֽג穾׶鴥׫זוָדֹ׷ ˖ ثؑ؎ٝꟚ㨣儗חِص٦ؙזせ⵸׾אֽג穾׶鴥׫װծ
 ずׄせ⵸ָ崧׸׋הֹךⵖ䖴ָדֹ׷
  27. 8PSLח勴⟝׾אֽ׵׸׷ val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .setConstraints(Constraints.Builder().setRequiresCharging(true).build()) .build()

    TFU$POTUSBJOUTד鏣㹀׃ג֮־׷ ⯍ꨵָ㨣ת׷הծ㹋遤ׁ׸׷ ˖ طحزٙ٦ؙחאזָ׏גְ׷儗ך׫ծ
 ⯍ꨵ儗ך׫㹋遤זוך♳ꣲָאֽ׵׸׷
  28. 8PSL.BOBHFSך堣腉稱➜ ˖ 8PSLך⣛㶷ؚٓؿָ⡲׸׷ ˖ UIFO ד8PSL׾籬־׵׸׷ ˖ 3Y+BWBך[JQ׫׋ְזֿהָדֹ׷ ˖ *OQVU.FSHFS׾⢪ֲ

    ˖ 8PSLח勴⟝׾אֽ׵׸׷ ˖ -JWF%BUBד➙ך朐䡾ָ鋅׵׸׷ ˖ 8PSLחةؚ׾אֽג穾׶鴥׫זוָדֹ׷ ˖ ثؑ؎ٝꟚ㨣儗חِص٦ؙזせ⵸׾אֽג穾׶鴥׫װծ
 ずׄせ⵸ָ崧׸׋הֹךⵖ䖴ָדֹ׷
  29. 8PSLחةؚ׾אֽג穾׶鴥׫זו ָדֹ׷ val taggedRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "WorkManager").toWorkData()) .addTag("tag")

    .build() WorkManager.getInstance().enqueue(taggedRequest) WorkManager.getInstance() .getStatusesByTag("tag") .observe(this, Observer<List<WorkStatus>> { workStatuses -> val workStatus = workStatuses?.getOrNull(0) ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { BEE5BH דةؚ鷄⸇ ˖ 㥨ֹחط٦يأل٦أ׾⡲׸׷
  30. 8PSLחةؚ׾אֽג穾׶鴥׫זו ָדֹ׷ val taggedRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "WorkManager").toWorkData()) .addTag("tag")

    .build() WorkManager.getInstance().enqueue(taggedRequest) WorkManager.getInstance() .getStatusesByTag("tag") .observe(this, Observer<List<WorkStatus>> { workStatuses -> val workStatus = workStatuses?.getOrNull(0) ?: return@Observer when (workStatus.state) { State.SUCCEEDED -> { HFU4UBUVTFT#Z5BH ד穾׶鴥׫ ˖ ➭ח׮ةؚ⽃⡘דٍؗٝإٕ׃׋׶⳿勻׷
  31. 8PSL.BOBHFSך堣腉稱➜ ˖ 8PSLך⣛㶷ؚٓؿָ⡲׸׷ ˖ UIFO  ד8PSL׾籬־׵׸׷ ˖ 3Y+BWBך[JQ׫׋ְזֿהָדֹ׷ ˖

    *OQVU.FSHFS׾⢪ֲ ˖ 8PSLח勴⟝׾אֽ׵׸׷ ˖ -JWF%BUBד➙ך朐䡾ָ鋅׵׸׷ ˖ 8PSLחةؚ׾אֽג穾׶鴥׫זוָדֹ׷ ˖ ثؑ؎ٝꟚ㨣儗חِص٦ؙזせ⵸׾אֽג穾׶鴥׫װծ
 ずׄせ⵸ָ崧׸׋הֹךⵖ䖴ָדֹ׷
  32. ثؑ؎ٝꟚ㨣儗חِص٦ؙזせ⵸׾אֽג 穾׶鴥׫װծⵖ䖴ָדֹ׷ val workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build()

    WorkManager.getInstance() .beginUniqueWork("hello", ExistingWorkPolicy.KEEP, workRequest ).enqueue() ずׄせ⵸ד8PSL׾㨣׭׋儗ךهٔء٦ ˖ ,&&1⯓ח㨣׭׋8PSL׌ֽ㹋遤 ˖ 3&1-"$&⯓ח㨣׭׋8PSL׾ٍؗٝإٕ׃ג⵴ꤐծ倜׃ְ8PSL׾Ꟛ㨣 ˖ "11&/%⯓ח㨣׭׋8PSLך䖓חծ⚕倯遤ֲկ
  33. 8PSL.BOBHFSך⣛㶷ꟼ⤘ BOESPJEBSDIXPSLXPSLSVOUJNFBMQIB ] BOESPJEBSDIMJGFDZDMFFYUFOTJPOT ]] BOESPJEBSDIMJGFDZDMFSVOUJNF  ]] BOESPJEBSDIDPSFDPNNPO 

    ]] BOESPJEBSDIDPSFSVOUJNF  ]] DPNBOESPJETVQQPSUTVQQPSUGSBHNFOU  ]] BOESPJEBSDIMJGFDZDMFDPNNPO  ]] BOESPJEBSDIMJGFDZDMFMJWFEBUB ]]] BOESPJEBSDIDPSFSVOUJNF  ]]] BOESPJEBSDIMJGFDZDMFMJWFEBUBDPSF  ]]]=BOESPJEBSDIDPSFDPNNPO  ]]=BOESPJEBSDIMJGFDZDMFWJFXNPEFM  ]=BOESPJEBSDIQFSTJTUFODFSPPNSVOUJNF ] BOESPJEBSDIQFSTJTUFODFSPPNDPNNPO ]]=DPNBOESPJETVQQPSUTVQQPSUBOOPUBUJPOT ] BOESPJEBSDIQFSTJTUFODFECGSBNFXPSL ]] DPNBOESPJETVQQPSUTVQQPSUBOOPUBUJPOT ]]=BOESPJEBSDIQFSTJTUFODFEC ]]=DPNBOESPJETVQQPSUTVQQPSUBOOPUBUJPOT ] BOESPJEBSDIQFSTJTUFODFEC  ] BOESPJEBSDIDPSFSVOUJNF  ]=DPNBOESPJETVQQPSUTVQQPSUDPSFVUJMT ̒-JWF%BUB ̒7JFX.PEFM ̒3PPN 3PPNח⣛㶷׃גְ׷
  34. &YFDVUPSװ+PC4DIFEVMFSזוך
 鼅䫛ٗآحؙ public @NonNull List<Scheduler> getSchedulers() { // Initialized at

    construction time. So no need to synchronize. if (mSchedulers == null) { mSchedulers = Arrays.asList( Schedulers.createBestAvailableBackgroundScheduler(mContext), new GreedyScheduler(mContext, this)); } return mSchedulers; } ˖ (SFFEZ4DIFEVMFSה DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS ׾⢪ֲ ˖ (SFFEZ4DIFEVMFSהכ ˖ DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS הכ ˖ 㹋遤ׅ׷➬穈׫׾寸׭׷ًاحس
  35. &YFDVUPSװ+PC4DIFEVMFSזוך
 鼅䫛ٗآحؙ public @NonNull List<Scheduler> getSchedulers() { // Initialized at

    construction time. So no need to synchronize. if (mSchedulers == null) { mSchedulers = Arrays.asList( Schedulers.createBestAvailableBackgroundScheduler(mContext), new GreedyScheduler(mContext, this)); } return mSchedulers; } ˖ (SFFEZ4DIFEVMFSה DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS ׾⢪ֲ ˖ (SFFEZ4DIFEVMFSהכ  ˖ DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS הכ ˖ 㹋遤ׅ׷➬穈׫׾寸׭׷ًاحس
  36. &YFDVUPSװ+PC4DIFEVMFSזוך
 鼅䫛ٗآحؙ public @NonNull List<Scheduler> getSchedulers() { // Initialized at

    construction time. So no need to synchronize. if (mSchedulers == null) { mSchedulers = Arrays.asList( Schedulers.createBestAvailableBackgroundScheduler(mContext), new GreedyScheduler(mContext, this)); } return mSchedulers; } ˖ (SFFEZ4DIFEVMFSה DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS׾⢪ֲ ˖ (SFFEZ4DIFEVMFSהכ  ˖ DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS הכ
  37. &YFDVUPSװ+PC4DIFEVMFSזוך
 鼅䫛ٗآحؙ public @NonNull List<Scheduler> getSchedulers() { // Initialized at

    construction time. So no need to synchronize. if (mSchedulers == null) { mSchedulers = Arrays.asList( Schedulers.createBestAvailableBackgroundScheduler(mContext), new GreedyScheduler(mContext, this)); } return mSchedulers; } ˖ (SFFEZ4DIFEVMFSה DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS׾⢪ֲ ˖ (SFFEZ4DIFEVMFSהכ  ˖ DSFBUF#FTU"WBJMBCMF#BDLHSPVOE4DIFEVMFS הכ
  38. DSFBUF#FTU"WBJMBCMF#BDLHSPVOE
 4DIFEVMFS static @NonNull Scheduler createBestAvailableBackgroundScheduler(@NonNull Context context) { Scheduler

    scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true;
  39. static @NonNull Scheduler createBestAvailableBackgroundScheduler(@NonNull Context context) { Scheduler scheduler; boolean

    enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { // Also catches the exception thrown if Play Services was not found on the device. scheduler = new SystemAlarmScheduler(context); "1*-FWFM⟃♳ד֮׸לծ 4ZTUFN+PC4DIFEVMFS׾⢪ֲ
  40. boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler

    = new SystemJobScheduler(context); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { // Also catches the exception thrown if Play Services was not found on the device. scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } "1*-FWFM劢弫ד֮׸לծ 'JSFCBTF+PC4DIFEVMFS׾ 鑐ׅ
  41. Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try

    { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { // Also catches the exception thrown if Play Services was not found on the device. scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } ׉׸ד׮تًד֮׸ל "MBSN.BOBHFS׾⢪ֲ
  42. DSFBUF#FTU"WBJMBCMF#BDLHSPVOE
 4DIFEVMFS static @NonNull Scheduler createBestAvailableBackgroundScheduler(@NonNull Context context) { Scheduler

    scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; DSFBUF#FTU"WBJMBCMF#BDLHSPVOE
 4DIFEVMFS דכせ⵸ך鸐׶ ⢪ִ׷♧殢ְְ4DIFEVMFS׾鵤ׅ
  43. 8PSL.BOBHFSךذأز @Test fun test() { val testDriver = WorkManagerTestInitHelper.getTestDriver() val

    workRequest = OneTimeWorkRequestBuilder<AddHelloWorker>() .setInputData(mapOf(KEY to "World").toWorkData()) .build() WorkManager.getInstance() .enqueue(workRequest) testDriver.setAllConstraintsMet(workRequest.id) val outputData = WorkManager.getInstance().synchronous().getStatusByIdSync(workRequest.id).out putData assertThat(outputData.getString(KEY, "none"), equalTo("Hello, World")) } 5FTU%SJWFS ׾⢪׏גず劍涸ח⹛ַ׃גذأزדֹ׷
  44. "OESPJE4VOPXFS BMQIB ך 8PSLFSך饯⹛ة؎ىؚٝ // Create and pre-populate the database.

    See this article for more details: // https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1#4785 private fun buildDatabase(context: Context): AppDatabase { return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) .addCallback(object : RoomDatabase.Callback() { override fun onCreate(db: SupportSQLiteDatabase) { super.onCreate(db) val request = OneTimeWorkRequestBuilder<SeedDatabaseWorker>().build() WorkManager.getInstance().enqueue(request) } }) .build() } 8PSLFSך饯⹛ة؎ىؚٝכ3PPNך%#ך PO$SFBUFד遤׏גְ׷
 䏝׃ַㄎל׸זְ
  45. "OESPJE4VOPXFS BMQIB ך 8PSLFSךⳢ椚 class SeedDatabaseWorker : Worker() { private

    val TAG = SeedDatabaseWorker::class.java.simpleName override fun doWork(): WorkerResult { val plantType = object : TypeToken<List<Plant>>() {}.type var jsonReader: JsonReader? = null return try { val inputStream = applicationContext.assets.open(PLANT_DATA_FILENAME) jsonReader = JsonReader(inputStream.reader()) val plantList: List<Plant> = Gson().fromJson(jsonReader, plantType) val database = AppDatabase.getInstance(applicationContext) database.plantDao().insertAll(plantList) WorkerResult.SUCCESS } catch (ex: Exception) { Log.e(TAG, "Error seeding database", ex) WorkerResult.FAILURE } finally { jsonReader?.close() } } } ٗ٦ٕؕח֮׷+40/׾ػ٦أ׃גծ3PPNחⰅ׸ גְ׷կ
  46. كأزفؙٓذ؍أ ˖ ءأذيָ،فָٔ穄✪׃׋ה׃ג׮ծ⹛⡲⥂鏾׃׋ְ ةأؙך׋׭ח⢪ֲկ ˖ %BUBؙٓأכر٦ةأز،דכזְךד׍ׯ׿ה3PPNז ו׾⢪ֲ ˖ 㹋遤דֹ׷堣⠓׾ֲֲַָ״ֲח$POTUSBJOUד勴⟝׾剅ֿ ֲկ


    ⢽ִל歗⫷ך⸇䊨ה،حفٗ٦س׾ׅ׷儗ח،حفٗ٦ سך8PSLחطحزٙ٦ָؙ䗳銲׌ה׃גֶֽלծ
 굲遤堣ח⛦׏גְ׷꟦ח歗⫷ך⸇䊨תדכ穄׻׏גծ籬 ָ׏׋׵،حفٗ٦س׃גֻ׸׷זוָדֹ׷ ⳿ⰩIUUQTZPVUVCF*S,P#'-X5/
  47. ⿫罋项俱 ˖ IUUQTEFWFMPQFSBOESPJEDPNUPQJDMJCSBSJFTBSDIJUFDUVSF XPSLNBOBHFS ˖ IUUQTXXXZPVUVCFDPNXBUDI W*S,P#'-X5/ ˖ IUUQTXXXZPVUVCFDPNXBUDI WQ&S5Z2Q"

    ˖ IUUQTDPEFMBCTEFWFMPQFSTHPPHMFDPNDPEFMBCTBOESPJE XPSLNBOBHFS ˖ IUUQTHJUIVCDPNHPPHMFTBNQMFTBOESPJEBSDIJUFDUVSF DPNQPOFOUTUSFFNBTUFS8PSL.BOBHFS4BNQMF