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

Android Oのバックグラウンド制限

Android Oのバックグラウンド制限

Android O のバックグラウンド制限について説明します。

参照:
- Background Check and Other Insights into the Android Operating System Framework (Google I/O '17)
https://www.youtube.com/watch?v=hbLAzwhBjFE
- バックグランド実行制限
https://developer.android.com/preview/features/background.html?hl=ja
- 暗黙的なブロードキャストの例外
https://developer.android.com/preview/features/background-broadcasts.html?hl=ja

979d93b360f80486b121486a9d063ad5?s=128

Hiroshi Kurokawa

June 02, 2017
Tweet

Transcript

  1. Android O ͷ
 όοΫάϥ΢ϯυ੍ݶ

  2. 2 I/Oηογϣϯ #BDLHSPVOE$IFDLBOE0UIFS*OTJHIUTJOUPUIF"OESPJE 0QFSBUJOH4ZTUFN'SBNFXPSL (PPHMF*0 https://www.youtube.com/watch?v=hbLAzwhBjFE

  3. 3 ੍ݶ w όοΫάϥ΢ϯυαʔϏεͷ੍ݶ w ϒϩʔυΩϟετͷ੍ݶ w όοΫάϥ΢ϯυ-PDBUJPO8J'J w "MFSU8JOEPXT

    4:45&.@"-&35@8*/%08
  4. 4 όοΫάϥ΢ϯυ੍ݶͱ͸ "OESPJE0Ͱ͸ɺϢʔβʔΤΫεϖϦΤϯεΛ޲্ͤ͞ΔͨΊʹɺΞϓϦ͕ όοΫάϥ΢ϯυͰ࣮ߦ͞Ε͍ͯΔͱ͖ͷಈ࡞Λ੍ݶ͍ͯ͠·͢ɻ https://developer.android.com/preview/features/background.html?hl=ja

  5. 5 ͳͥʁ w 3".Ϛωʔδϝϯτ w লిྗ

  6. όοΫάϥ΢ϯυαʔϏε ͷ੍ݶ 6

  7. 7 όοΫάϥ΢ϯυαʔϏεͷ੍ݶ wՄࢹΞΫςΟϏςΟ͕͋Δ wՄࢹΞΫςΟϏςΟ͕ͳ͍ ˠϑΥΞόοΫ྆ํͷαʔϏεΛ࡞ΕΔ ˠϑΥΞάϥ΢ϯυ ˠόοΫάϥ΢ϯυ ˠόοΫάϥ΢ϯυαʔϏε͸਺෼Ͱఀࢭ͢Δ UBSHFU4EL7FSTJPO͕0ͷͱ͖ͷΈʂ

  8. 8 ࣮ߦྫʢόοΫάϥ΢ϯυαʔϏεʣ public class MainActivity extends AppCompatActivity { @Override protected

    void onCreate(Bundle savedInstanceState) { service = new Intent(this, MyService.class); startService(service); public class MyService extends Service { private Timer timer; private final TimerTask task = … @Override public int onStartCommand(Intent intent, int flags, int startId) { timer = new Timer(); timer.scheduleAtFixedRate(task, 0, TimeUnit.SECONDS.toMillis(10));
  9. 9 ࣮ߦྫʢόοΫάϥ΢ϯυαʔϏεʣ

  10. 10 ࣮ߦྫʢϑΥΞάϥ΢ϯυαʔϏεʣ public class MyService extends Service { private Timer

    timer; private final TimerTask task = … @Override public int onStartCommand(Intent intent, int flags, int startId) { timer = new Timer(); timer.scheduleAtFixedRate(task, 0, TimeUnit.SECONDS.toMillis(10)); PendingIntent pendingIntent = … Notification notification = … startForeground(startId, notification);
  11. 11 ࣮ߦྫʢϑΥΞάϥ΢ϯυαʔϏεʣ

  12. 12 ϑΥΞάϥ΢ϯυʹ͢Δʹ͸ʁ ͦͷͨΊɺ"OESPJE0Ͱ͸৽͍͠ϝιου /PUJpDBUJPO.BOBHFSTUBSU4FSWJDF*O'PSFHSPVOE Λಋೖ͍ͯ͠·͢ɻ
 ͜ͷϝιουΛݺͼग़͢͜ͱ͸ɺTUBSU4FSWJDF Λݺͼग़ͯ͠όοΫάϥ΢ ϯυͰαʔϏεΛ࡞੒͠ɺ௚ޙʹͦͷαʔϏεͷTUBSU'PSFHSPVOE ϝιο υΛݺͼग़ͯ͠αʔϏεΛϑΥΞάϥ΢ϯυʹϓϩϞʔτ͢Δ͜ͱͱಉ౳Ͱ

    ͢ɻ ݟͨͱ͜ΖɺͦΕΒ͖͠ϝιου͸ͳ͍ɻࠓޙ௥Ճ͞ΕΔʁ
 $POUFYU8SBQQFSTUBSU'PSFHSPVOE4FSWJDF *OUFOU ͸͋ͬͨ https://developer.android.com/preview/features/background.html?hl=ja
  13. ϒϩʔυΩϟετͷ੍ݶ 13

  14. 14 ϒϩʔυΩϟετͷ੍ݶͱ͸ "OESPJE0Λର৅ʹ͍ͯ͠ΔΞϓϦ͸ɺ҉໧తͳϒϩʔυ Ωϟετʹର͢ΔϒϩʔυΩϟετϨγʔόʔΛϚχϑΣ ετͰొ࿥Ͱ͖ͳ͘ͳΓ·ͨ͠ɻ
 ҉໧తͳϒϩʔυΩϟετͱ͸ɺλʔήοτʹ͢ΔΞϓϦ Λ໌֬ʹࢦఆ͠ͳ͍ϒϩʔυΩϟετͰ͢ɻ https://developer.android.com/preview/features/background.html?hl=ja

  15. 15 ର৅ͱͳΔϒϩʔυΩϟετ ର৅ɿ w$0//&$5*7*5:@"$5*0/ w"$5*0/@/&8@1*$563& w"$5*0/@/&8@7*%&0 ର৅֎ɿ w#005@$0.1-&5&% w-0$"-&@$)"/(&% w64#@%&7*$&@"55"$)&%

    w)&"%4&5@1-6(
 FUD IUUQTEFWFMPQFSBOESPJEDPNQSFWJFXGFBUVSFTCBDLHSPVOECSPBEDBTUTIUNM IMKB
  16. ୅ସखஈ 16

  17. 17 ୅ସखஈ w ఆظతͳνΣοΫʹ͸+PC4DIFEVMFS΍"MBSN.BOBHFS w '$.ͳͲͷϓογϡ௨஌Ͱ୅ସ͢Δ͜ͱ΋Մೳ͔΋ w $POUFU1SPWJEFSͷ಺༰Λಉظ͍ͨ͠ͳΒ4ZOD"EBQUFS w ϢʔβʔʹݟͤΔඞཁ͕͋ΔͳΒϑΥΞάϥ΢ϯυαʔϏε

  18. 18 Alarms, Jobs, Services ͷ࢖͍෼͚

  19. 19 JobIntentService?

  20. 20 JobIntentService? w *OUFOU4FSWJDFͷΑ͏ʹ࢖͑ͯ w +PC4DIFEVMFS͕ϋϯυϧͯ͘͠ΕΔ w 8BLFGVM-PDL΋Α͠ͳʹ΍ͬͯ͘ΕΔ w 0Ҏલ͓ΑͼҎ߱Ͱ࢖͑Δ

    w 0ͷϩʔϯνલʹग़Δ͸ͣʂ
  21. 21 ·ͱΊ w "OESPJE0ͷόοΫάϥ΢ϯυ੍ݶ w όοΫάϥ΢ϯυαʔϏε w ҉໧తϒϩʔυΩϟετ w ୅ସखஈ

    w ϑΥΞάϥ΢ϯυαʔϏε w +PC4DIFEVMFS"MBSN.BOBHFS4ZOD"EBQUFS w ϓογϡ௨஌ w +PC*OUFOU4FSWJDF
  22. 22 ·ͱΊ ϢʔβʔʹΞϯΠϯετʔϧ͞Εͳ͍Α͏ʹ
 ి஑ͱ3".ʹ༏͍͠ΞϓϦʹ͠·͠ΐ͏ ɹɹ