Cookpad TechKitchen#6-android-with-ml-and-scheduler

11f1c6f9a26793f33d93eed3a97f4a6c?s=47 kazy1991
March 23, 2017

Cookpad TechKitchen#6-android-with-ml-and-scheduler

11f1c6f9a26793f33d93eed3a97f4a6c?s=128

kazy1991

March 23, 2017
Tweet

Transcript

  1. ػցֶशͱ+PC4DIFEVMFSΛ࢖ͬͨϓϩμΫτ։ൃ ٢ాສً LB[Z  αʔϏε։ൃ෦

  2. ؔΘͬͨϓϩμΫτ ʮྉཧ͖Ζ͘ʯ ྉཧࣸਅ͚ͩ͋ͭΊͯه࿥͢Δ

  3. ྉཧ͖Ζ͘ͷ࢓૊Έ  $PPLQBEΞϓϦ͸෼ִؒͰ৽نࣸਅΛ୳͢  ৽نࣸਅ͕ݟ͔ͭͬͨ৔߹͸ɺྉཧ൑ఆ͢Δ  ྉཧͱ൑ఆ͞ΕͨࣸਅΛΞοϓϩʔυ͢Δ

  4. ྉཧ͖Ζ͘ͷٕज़తͳಛ௃  ػցֶशΛར༻ͨ͠ྉཧը૾൑ఆ  +PC4DIFEVMFSͷϓϩμΫγϣϯͰͷར༻

  5. ػցֶशͱωΠςΟϒΞϓϦ

  6. ֶशϞσϧΛͲ͜ʹஔ͔͘  ୺຤಺ʹֶशϞσϧΛ಺ଂ͠ɺΞϓϦ಺Ͱ൑ఆ͢Δ  αʔόʔଆʹϞσϧΛஔ͍ͯɺ"1*Ͱ݁ՌΛड͚औΔ

  7. ୺຤಺ʹֶशϞσϧΛஔ͘৔߹  ྑ͍఺ - ߴ଎ - ઃܭ͕γϯϓϧ - ࢪࡦͷࣗ༝౓͕ߴ͍

  8. ୺຤಺ʹֶशϞσϧΛஔ͘৔߹  ྑ͘ͳ͍఺ - ֶशϞσϧΛখ͘͢͞Δ౒ྗ͕ඞཁ - Ϟσϧͷվળ͕ΞϓϦͷϦϦʔεαΠΫϧʹґଘ - NDKΛ࢖͏։ൃ͕ආ͚ΒΕͳ͍..?

  9. αʔόʔଆʹֶशϞσϧΛஔ͘৔߹  ྑ͍఺ - ϞσϧͷαΠζ͕େ͖ͯ͘΋໰୊ͳ͍ - ॊೈʹϞσϧͷࠩ͠ସ͕͑Մೳ

  10. αʔόʔଆʹֶशϞσϧΛஔ͘৔߹  ྑ͘ͳ͍఺ - ൑ఆϑϩʔ͕ෳࡶʹͳΓ͕ͪ - ௨৴ྔ͕ൺֱతଟ͘ͳΔ

  11. ΞʔΩςΫνϟͷ࿩

  12. εέʔϧ͠ͳ͍  ॳظͷΞʔΩςΫνϟ

  13. T

  14. ॳظͷΞʔΩςΫνϟͷ໰୊఺  ը૾Ξοϓϩʔυ΍൑ఆͷ*0଴ͪʹΑͬͯ
 "1*αʔόʔͷXPSLFS͕࢖͍੾ͬͯ͠·͏  େྔͷը૾͕DPPLQBEͷ"1*αʔόʔʹૹ৴͞Εɺ
 τϥϑΟοΫ͕૿Ճ͢Δ

  15. ݱࡏͷΞʔΩςΫνϟ

  16. None
  17. None
  18. ৽ΞʔΩςΫνϟͰมߋͨ͠఺  ඇಉظ ϙʔϦϯά Ͱ൑ఆ݁ՌΛड͚औΔ  ը૾ͷΞοϓϩʔυ͸͢΂ͯ4ʹ௚઀౤͛Δ

  19. ݁ՌΛඇಉظͰड͚औΔ࢓૊Έ  ΞϓϦ͔Βը૾Λ௚઀4ʹΞοϓ͢Δ  4ʹը૾͕Ξοϓ͞ΕΔͱ424ʹΩϡʔ͞ΕΔ  ֶशϞσϧ͕ࡌͬͨQZUIPOαʔόʔ͕ը૾Λड͚औΔ  ྉཧը૾͔൑ఆͯ͠ɺ%#ʹ݁ՌΛॻ͖ࠐΉ 

    ΞϓϦ͔Β"1*Λ௨ͯ݁͠ՌΛಡΈʹߦ͘
  20. None
  21. ػցֶशͱωΠςΟϒΞϓϦ  ϞσϧΛ୺຤಺ʹ͍ΕΔͷ͔ɺ"1*ܦ༝Ͱར༻͢Δ͔  "1*ܦ༝ͷ৔߹ಉظతͳ΍ΓऔΓ͸ݫ͍͠  εέʔϧ͢ΔΞʔΩςΫνϟΛؤு࣮ͬͯ૷͢Δ

  22. +PC4DIFEVMFSͷجຊͱUJQT

  23. +PC4DIFEVMFS  -PMMJQPQͰొ৔ͨ͠ൺֱత৽͍͠"1*  4FSWJDFΛ೚ҙͷλΠϛϯάͰɺىಈ͢Δ͜ͱ͕ग़དྷΔ
 δϣϒεέδϡʔϥʔ  DPPLQBEΞϓϦ ྉཧ͖Ζ͘ Ͱ͸+PC4DIFEVMFSΛ࠾༻ͨ͠

  24. +PC4DIFEVMFSαϯϓϧ 4FSWJDFଆ public class MyJobService extends JobService {
 
 @Override


    public boolean onStartJob(JobParameters job) { // ͜͜ʹॲཧΛهड़͢Δ
 return false;
 }
 
 @Override
 public boolean onStopJob(JobParameters job) {
 return false;
 }
 } <service
 android:name=".MyJobService"
 android:exported="true"
 android:permission="android.permission.BIND_JOB_SERVICE" />
  25. +PC4DIFEVMFSαϯϓϧ 4FSWJDFଆ public class MyJobService extends JobService {
 @Override
 public

    boolean onStartJob(JobParameters params) { // ͜͜͸ϝΠϯεϨου
 tooHeavyJob()
 .subscribeOn(Schedulers.io())
 .subscribe(result -> {
 // Կ͔ߋ৽ॲཧͳͲΛߦ͏
 jobFinished(params, false);
 // δϣϒ͕ࣦഊͨ͠৔߹͸trueΛ౉͢ͱ࠶εέδϡʔϧ
 });
 // ಉظॲཧͷ৔߹͸false/ඇಉظॲཧͷ৔߹͸trueΛฦ͢
 return true;
 }
 
 @Override
 public boolean onStopJob(JobParameters params) { // δϣϒ͕׬ྃ͢ΔલʹγεςϜ͕Ωϟϯηϧ͢Δͱݺ͹ΕΔ
 return false;
 }
 }
  26. +PC4DIFEVMFSαϯϓϧ εέδϡʔϧॲཧ 
 public class MyJobService extends JobService {
 


    private static final int PERIODIC_JOB_ID = 1;
 
 public static void setPeriodicSchedule(Context context) {
 JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
 
 JobInfo jobInfo = new JobInfo.Builder(PERIODIC_JOB_ID,
 new ComponentName(context, MyJobService.class))
 .setPeriodic(TimeUnit.MINUTES.toMillis(30))
 .setPersisted(true)
 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
 .build();
 scheduler.schedule(jobInfo);
 }
 
 public static void cancelPeriodicSchedule(Context context) {
 JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
 scheduler.cancel(PERIODIC_JOB_ID);
 } }
  27. +PC4DIFEVMFSͰεέδϡʔϧʹར༻Ͱ͖Δ৚݅  ࠷େకΊ੾Γ࣌ؒ TFU0WFSSJEF%FBEMJOF   ࠷௿஗Ԇ࣌ؒ TFU.JOJNVN-BUFODZ  

    όοΫΦϑϦτϥΠํ਑ TFU#BDLPGG$SJUFSJB   ௨৴؀ڥͷ੍໿ TFU3FRVJSFE/FUXPSL5ZQF   ॆి؀ڥͷ੍໿ TFU3FRVJSFT$IBSHJOH   ΞΠυϧঢ়ଶͷ੍໿ TFU3FRVJSFT%FWJDF*EMF   ܁Γฦ͠ͷεέδϡʔϦϯά TFU1FSJPEJD   ࠶ىಈ࣌ͷӬଓԽ TFU1FSTJTUFE
  28. +PC4DIFEVMFSʹύϥϝʔλΛ౉͢  +PC*OGP#VJMEFSTFU&YUSBT 1FSTJTUBCMF#VOEMFFYUSBT 
 PersistableBundle bundle = new PersistableBundle();


    JobInfo jobInfo = new JobInfo.Builder(JOB_TAG,
 new ComponentName(this, MyJobService.class))
 .setExtras(bundle)
 .build(); public class MyJobService extends JobService {
 @Override
 public boolean onStartJob(JobParameters params) {
 PersistableBundle bundle = params.getExtras();
 // PersistableBundle͸εέδϡʔϧ࣌ʹӬଓԽ͞ΕΔͷͰɺ
 // ͜͜Ͱॻ͖׵͑ͯ΋࣍ճͷjobʹ͸൓ө͞Εͳ͍
 return false;
 }
 }  +PC1BSBNFUFSTHFU&YUSBT
  29. εέδϡʔϧঢ়گΛίʔυͰ֬ೝ͢Δ  +PC4DIFEVMFSHFU"MM1FEJOH+PCT  εέδϡʔϧ͞Ε͍ͯΔKPC*OGPϦετ͕ड͚औΕΔ  εέδϡʔϧͨ͠ࡍʹ౉ͨ͠*%Λൺֱ͢Δ 
 public static

    boolean isPending(Context context, int serviceId) {
 JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
 List<JobInfo> pendingJobList = scheduler.getAllPendingJobs();
 for (JobInfo jobInfo : pendingJobList) {
 if (serviceId == jobInfo.getId()) {
 return true;
 }
 }
 return false;
 }
  30. BECίϚϯυͰ+PC4DIFEVMFSͷঢ়ଶΛ֬ೝ͢Δ  δϣϒεέδϡʔϥʔʹొ࿥͞ΕͯΔλεΫҰཡ  ࣮ߦ଴ͪͷλεΫҰཡ  ࣮ߦ͞ΕͨλεΫͷώετϦʔҰཡ  04όʔδϣϯʹΑͬͯද͕ࣔ΍΍ҧ͏ 


    adb shell dumpsys jobscheduler

  31. +PC4DIFEVMFS  ྑ͍఺  04ඪ४ͳͷͰ৴པ౓͸ߴ͍  ࡉ͔͍εέδϡʔϧ৚͕݅ࢦఆͰ͖Δ  ࠶ىಈͯ͠΋ӬଓԽ͞ΕΔ࢓૊Έ͕͋Δ 

    ϚϧνϢʔβʔʹରԠ  ϖϯσΟϯάதͷ+PCҰཡ͕औಘͰ͖Δ
  32. +PC4DIFEVMFS  ྑ͘ͳ͍఺   ཁٻ͞ΕΔ"QJϨϕϧ Ҏ্ ͕ߴ͍  ϓϩμΫγϣϯͰͷར༻࣮੷͕গͳ͍

     σόοά͕ͱʹ͔͘େม
  33. +PC4DIEVMFS։ൃͰؾΛ͚͍ͭͨϙΠϯτ

  34. ΞϓϦͷߋ৽Ͱεέδϡʔϧ͕ফ͑Δ  ݱ৅  ઃఆͨ͠εέδϡʔϧ͕ফ͍͑ͯΔ  ࠶ݱ৚݅  ܥͷ୺຤ͰΞϓϦΛߋ৽͢ΔͱϦηοτ͞ΕΔ 

    ରԠࡦ  ύοέʔδͷߋ৽Λݕ஌ͯ͠࠶ઃఆ͢Δ
  35. ύοέʔδߋ৽ΠϕϯτΛϋϯυϦϯά͢Δ <receiver android:name=".receiver.PackageReplacedBroadcastReceiver">
 <intent-filter>
 <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
 </intent-filter>
 </receiver> @Override


    public void onReceive(Context context, Intent intent) {
 super.onReceive(context, intent);
 String action = intent.getAction();
 if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
 // εέδϡʔϧ͞Ε͍ͯΔ͔֬ೝ͢Δɻ
 }
 }
  36. Ұ౓͖Γͷδϣϒ͕ճىಈ͢Δ  ݱ৅  Ұ౓͖Γͷεέδϡʔϧͷ͸͕ͣෳ਺ճىಈ͢Δ  ࠶ݱ৚݅  /ະຬͷશͯͷ୺຤ 

    +PCͷ࣮ߦ࣌ؒΑΓ%FBEMJOF͕୹͍ͱෳ਺ճىಈ͢Δ  ରԠࡦ  %FBEMJOFΛ৳͹͢ɺνΣοΫػߏΛ༻ҙ͢Δ IUUQTUBDLPWFSGMPXDPNRVFTUJPOTKPCTDIFEVMFSQPTUJOHKPCTUXJDFOPUFYQFDUFE
  37. ະຬʹ΋ରԠ͍ͨ͠

  38. ࢒Γ͸ɺ TQFBLFSEFDLDPNLB[ZESPJELBJHJ PS͜ͷ͋ͱͷ࠙਌ձͰ