More Related Content More from Somkiat Khitwongwattana (18) What's new in Android O @ Google I/O Extended Bangkok 20177. Background Service Limitations
• App ที่มี Activity แสดงอยู่บนหน้าจอถือว่าเป็น Foreground App
• App ที่มี Foreground Service ทํางานอยู่ถือว่าเป็น Foreground App
• App ที่เชื่อมต่อกับ Foreground App ก็ถือว่าเป็น Foreground App
• นอกเหนือจากนี้ถือว่าเป็น Background App
อะไรที่เป็น Background App ซวย!!
9. Background Service Limitations
• เรียกใช้งาน FCM แบบ High Priority
• รับ Broadcast ที่เกี่ยวกับ User โดยตรง เช่น SMS
• เรียกใช้งาน Notification โดยกําหนด Pending Intent ไว้ด้วย
• จะไม่ถูกสั่งให้หยุดทํางาน เพราะติดต่อกับส่วนที่แสดงผลต่อผู้ใช้โดยตรง
เว้นแต่ว่า Background App นั้น...
10. • Broadcast Receiver ที่เป็น Implicit Broadcast
ที่ประกาศไว้ใน Android Manifest จะไม่ทํางานอีกต่อไป
• มี Implicit Broadcast บางตัวที่ได้รับการยกเว้น
Broadcast Limitations
Broadcast Receiver ก็ซวยเช่นกัน
11. • ACTION_LOCKED_BOOT_COMPLETED
• ACTION_BOOT_COMPLETED
• ACTION_LOCALE_CHANGED
• ACTION_HEADSET_PLUG
• ACTION_MEDIA_MOUNTED
Broadcast Limitations
ตัวอย่าง Implicit Broadcast ที่ไม่ซวย
• ACTION_USB_DEVICE_ATTACHED
• ACTION_USB_DEVICE_DETACHED
• ACTION_NEW_OUTGOING_CALL
• SMS_RECEIVED_ACTION
• ฯลฯ
ดูเพิ่มเติมได้ที่
https://developer.android.com/preview/features/background-broadcasts.html
14. Background Location Limits
• App ที่มี Activity แสดงอยู่บนหน้าจอถือว่าเป็น Foreground App
• App ที่มี Foreground Service ทํางานอยู่ถือว่าเป็น Foreground App
• App ที่เชื่อมต่อกับ Foreground App ก็ถือว่าเป็น Foreground App
• นอกเหนือจากนี้ถือว่าเป็น Background App
อะไรที่เป็น Background App ก็ซวยเหมือนเดิม
15. • ทําให้ App เป็น Foreground App ซะ อย่างเช่นทําเป็น Foreground Service ที่ผูกเข้ากับ
Notification เพื่อให้ผู้ใช้รู้ว่ากําลังจับตําแหน่งอยู่
• แทนวิธีแบบเดิมๆที่ทําเป็น Background App แล้วคอยจับตําแหน่งอยู่เงียบๆตลอดเวลา
How do we deal with it?
วิธีการรับมือ
57. Adaptive Icons
• Foreground และ Background ควรมีขนาด 108x108 dp
• พื้นที่ในการแสดงภาพของ Foreground ควรอยู่ใน 72x72dp
• ระบบจะเผื่อพื้นที่ไว้อีก 18dp สําหรับแสดงเอฟเฟคเคลื่อนไหว
• เฉพาะ API 26 ขึ้นไปเท่านั้น
Should know
70. Multi-display Support
• การทํางานเหมือน Multi-Window
• แอพไหนรองรับ Multi-Window ก็จะรองรับ Multi-display
• ออกแบบ Layout ให้รองรับการปรับขนาดหน้าจอแบบอิสระ
• จัดการกับ Lifecycle ให้ดีๆ
• อย่าลืมเรื่อง Configuration Changes
• อย่าลืมเรื่อง Instance State ด้วยเหมือนกัน
71. Layout Margins & Padding
• layout_marginVertical = layout_marginTop + layout_marginBottom
• layout_marginHorizontal = layout_marginLeft + layout_marginRight
• paddingVertical = paddingTop + paddingBottom
• paddingHorizontal = paddingLeft + paddingRight
ไม่มีผลกับ
layout_marginStart, layout_marginEnd, paddingStart และ paddingEnd.
77. References
Android O Developer Preview
https://developer.android.com/preview/index.html
Android O Features and APIs
https://developer.android.com/preview/api-overview
Migrating Apps to Android O
https://developer.android.com/preview/migration.html
Sample Codes
https://developer.android.com/samples/index.html