package Ġcom . il if esm art . weather Ċ Ċ import Ġandroid . app . job . Job Info Ċ import Ġandroid . app . job . Job Scheduler Ċ import Ġandroid . content . Component Name Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Build Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . annotation . Requires Api Ċ import Ġcom . services . My JobService Ċ import Ġkotlinx . android . synt hetic . main . activity _ job .* Ċ import Ġjava . util . concurrent . atomic . Atomic Integer Ċ Ċ class ĠJob Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĉĊ ĉ private Ġlateinit Ġvar Ġscheduler : Job Scheduler Ċ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ set ContentView ( R . layout . activity _ job ) ĊĉĉĊĉ ĉ /* Ċĉ ĉ * Ġ 1 . Ġ æŀĦå»º Job Info Ċĉ ĉ * Ġ 2 . ĠéĢļè¿ĩ schedule å°Ĩ Job Infos ä¼ł éĢģ åĪ° Job Scheduler Ċĉ ĉ * Ġ 3 . Ġå½ĵ æĿ¡ä»¶ æ»¡è¶³ æĹ¶ ï¼Į ç³»ç»Ł å°Ĩ ä¼ļ æī§è¡Į åºĶçĶ¨ åĨħ çļĦ JobService ä¸ĬçļĦ Job Ċĉ ĉ * Ċĉ ĉ * Ġschedule å¤±è´¥ åİŁåĽł Ċĉ ĉ * Ġ 1 . Ġ æĹł æķĪ çļĦåıĤæķ° Ċĉ ĉ * Ġ 2 . Ġ å¤ª å¤ļ jobs Ċĉ ĉ * Ġ 3 . Ġ çŁŃ æĹ¶éĹ´ schedule å¤ª å¤ļ jobs Ċĉ ĉ * Ċĉ ĉ * Ġå¦Ĥæŀľ schedule ä¸Ģä¸ª åĲĮ id çļĦ job ï¼Į å¦Ĥæŀľ å½ĵåīį id çļĦ æŃ£åľ¨ æī§è¡Į ï¼Į éĤ£ä¹Ī åħ¶ å°Ĩ åģľæŃ¢ Ċĉ ĉ * Ġ*/ Ċĉ ĉ scheduler Ġ= Ġget System Service ( JOB _ SCHEDUL ER _ SERVICE ) Ġas ĠJob Scheduler ĊĉĉĊĉ ĉ log . setOnClickListener Ġ{ Ċĉĉ ĉ schedule Job Info ( this , ĠMy JobService . Job ID _ LOG ) Ċĉ ĉ } ĊĉĉĊĉ ĉ toast . setOnClickListener Ġ{ Ċĉĉ ĉ schedule Job Info ( this , ĠMy JobService . Job ID _ TO AST , ĠBundle (). apply Ġ{ Ċĉĉĉ ĉ putString ( My JobService . CONST _ TO AST _ MESSAGE _ KEY , Ġ" Toast Ġhere Ġ.. ") Ċĉĉ ĉ }) Ċĉ ĉ } ĊĉĉĊĉ ĉ print . setOnClickListener Ġ{ Ċĉĉ ĉ schedule Job Info ( this , ĠMy JobService . JOB ID _ PRINT ) Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ fun Ġschedule Job Info ( context : Context , Ġjob Id : Int , Ġbundle : Bundle ?= null ) Ġ{ ĊĉĉĊĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) Ġ{ Ċĉĉ ĉ My JobService . get Job Info ( context , Ġjob Id , Ġbundle )?. apply Ġ{ Ċĉĉĉ ĉ scheduler . schedule ( this ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ fun Ġschedule Job Info ( job ID : Int ) Ġ{ ĊĊĉ ĉ with ( Job Info . Builder ( job ID , Ġcomponent Name )) Ġ{ Ċ // ĉĉ ĉ setMinimum Latency ( 5 0 0 0 ) Ċĉĉ ĉ set Required Network Type ( Job Info . NETWORK _ TYPE _ ANY ) Ċ // ĉĉ ĉ set Override Deadline ( 1 0 _ 0 0 0 ) Ċĉĉ ĉ set Backoff Criteria ( 1 0 0 0 L , ĠJob Info . BACK OFF _ POLICY _ LINEAR ) Ċĉ ĉ }. build (). apply Ġ{ ĊĉĉĊĉ ĉ } Ċ ĉ } Ċ }