Android : How to detect App foreground/background
วันนี้เรามีอีกวิธีในการตรวจสอบว่าแอปฯของเราอยู่ในสถานะทำงานอยู่ (foreground) หรือถูกปิดหรือย่อให้อยู่เบื้องหลัง (Background) โดยวิธีนี้เราจะเรียกใช้ Lifecycle Observer ที่มากับ androidx (androidx.lifecycle.OnLifecycleEvent) ตรวจจับการทำงานของ Event ของแอปฯ การเรียกใช้เราประกาศครั้งเดียวตอนเปิดแอปฯ แล้วตัว lifecycle จะคอยจับ event ให้เรา ดังนี้ Related posts: Android : เริ่มต้นพัฒนา Android Mobile Application ตอนที่ 1 Android : Clear Android...