ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
พื้นที่เก็บข้อมูลแอปที่แคชไว้
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Android 11 QPR3 ขึ้นไปรองรับเครื่องมือแช่แอปแคชไว้ ฟีเจอร์นี้จะหยุดการดำเนินการสำหรับกระบวนการที่แคชไว้และลดการใช้ทรัพยากรโดยแอปที่ทำงานผิดปกติซึ่งอาจพยายามทำงานขณะที่แคชไว้ เฟรมเวิร์กจะหยุดแอปที่แคชไว้ชั่วคราวโดยการย้ายข้อมูลกระบวนการของแอปไปยัง cgroup ที่หยุดไว้ชั่วคราว ซึ่งจะช่วยลดการใช้ CPU ที่ทำงานอยู่และไม่ได้ทำงานเมื่อมีแอปที่แคชไว้ซึ่งทำงานอยู่
คุณเปิดใช้โปรแกรมหยุดแอปชั่วคราวได้โดยใช้ Flag การกําหนดค่าระบบหรือตัวเลือกสําหรับนักพัฒนาแอป
ใช้เครื่องมือหยุดแอป
ตัวหยุดแอปแคชไว้ใช้ประโยชน์จากตัวหยุด cgroup v2 ของเคอร์เนล อุปกรณ์ที่มาพร้อมกับเคอร์เนลที่เข้ากันได้จะเปิดใช้ (ไม่บังคับ) ได้ โดยเปิดใช้ตัวเลือกสำหรับนักพัฒนาแอป "ระงับการดำเนินการสำหรับแอปที่แคชไว้" หรือตั้งค่า Flag การกำหนดค่าอุปกรณ์ activity_manager_native_boot use_freezer
เป็น true
เช่น
adb shell device_config put activity_manager_native_boot use_freezer true && adb reboot
ระบบจะปิดใช้การแช่แข็งเมื่อตั้งค่า Flag use_freezer
เป็นเท็จหรือปิดใช้ตัวเลือกสำหรับนักพัฒนาซอฟต์แวร์ คุณสลับการตั้งค่านี้ได้โดยการเปลี่ยนการกำหนดค่าอุปกรณ์ในรุ่นหรืออัปเดตซอฟต์แวร์
เครื่องมือหยุดแอปชั่วคราวจะไม่แสดง API อย่างเป็นทางการ (และไม่มีไคลเอ็นต์การติดตั้งใช้งานอ้างอิง) แต่จะใช้ API ของระบบที่ซ่อนอยู่ setProcessFrozen
และ enableFreezer
โปรดดูรายละเอียดเกี่ยวกับ API เหล่านี้ที่ ActivityManagerProcess.java
และ ActivityManagerService API นอกจากนี้ นักพัฒนาแอปยังดูโค้ดไคลเอ็นต์ใน ActivityManager
เพื่อการทดสอบได้ด้วย
จัดการฟีเจอร์ที่กำหนดเอง
โดยปกติแล้ว กระบวนการจะไม่ทำงานเมื่อแคชไว้ แต่แอปบางแอปอาจมีฟีเจอร์ที่กำหนดเองซึ่งรองรับกระบวนการที่คาดว่าจะทำงานขณะแคชไว้ เมื่อเปิดใช้โปรแกรมแช่แอปในอุปกรณ์ที่ใช้แอปดังกล่าว ระบบจะหยุดกระบวนการแคชไว้และอาจทำให้ฟีเจอร์ที่กำหนดเองไม่ทำงาน
วิธีแก้ปัญหาคือ หากแอปมีกระบวนการที่ต้องทํากิจกรรมขณะแคชอยู่ ให้เปลี่ยนสถานะกระบวนการเป็น "ไม่ได้แคช" (เช่น Bound ForeGround Service (BFGS) หรือเบื้องหน้า) ก่อนที่กระบวนการจะต้องทํางานใดๆ เพื่ออนุญาตให้แอปยังคงทํางานอยู่
ทดสอบเครื่องมือแช่แข็งแอป
หากต้องการตรวจสอบว่าเครื่องมือหยุดแอปทำงานตามที่ต้องการ ให้ใช้แหล่งข้อมูลต่อไปนี้
ตรวจสอบรายการกระบวนการที่หยุดทำงานโดยใช้คำสั่ง adb shell dumpsys activity
และ grep สำหรับ Apps frozen:
ตรวจสอบว่ามีไฟล์ /sys/fs/cgroup/uid_0/cgroup.freeze
หรือไม่
ดู logcat ซึ่งแสดงรายการที่หยุดและเลิกหยุดทำงานทุกครั้งที่กระบวนการย้ายเข้าหรือออกจากช่องเก็บข้อมูล เช่น
adb logcat | grep -i "\(freezing\|froze\)"
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Cached apps freezer\n\nAndroid 11 QPR3 or higher supports the cached apps\nfreezer. This feature stops execution for cached processes and reduces resource\nusage by misbehaving apps that might attempt to operate while cached. The\nframework freezes cached apps by migrating their processes into a frozen cgroup;\nthis reduces active and idle CPU consumption in presence of active cached apps.\nThe app freezer can be enabled using a system configuration flag or a developer\noption.\n\nImplement the apps freezer\n--------------------------\n\nThe cached apps freezer leverages the kernel cgroup v2 freezer. Devices shipping\nwith a compatible kernel can (optionally) enable it. To do so, enable the\ndeveloper option \"Suspend execution for cached apps\" or set the device config\nflag `activity_manager_native_boot use_freezer` to `true`. For example: \n\n adb shell device_config put activity_manager_native_boot use_freezer true && adb reboot\n\nThe freezer is disabled when the flag `use_freezer` is set to false or the\ndeveloper option is disabled. You can toggle this setting by changing a device\nconfiguration in a software release or update.\n\nThe apps freezer doesn't expose official APIs (and doesn't have a reference\nimplementation client), but does use the hidden system APIs `setProcessFrozen`\nand `enableFreezer`. For details on these APIs, refer to ActivityManager's\n`Process.java` and the ActivityManagerService API. Developers can also refer to\nthe client code in `ActivityManager` for experiments.\n\nHandle custom features\n----------------------\n\nTypically, processes aren't expected to do any work when cached, but some apps\nmight have custom features supported by processes that are expected to run while\ncached. When the apps freezer is enabled on a device running such an app, the\ncached processes are frozen and might prevent custom features from working.\n\nAs a workaround, if an app has a process that needs to perform activities while\ncached, change the process status to non-cached (such as Bound ForeGround\nService (BFGS) or foreground) before the process needs to do any work to allow\nthe app to remain active.\n\nTest the apps freezer\n---------------------\n\nTo verify the app freezer is working as intended, use the following resources:\n\n- Check for a list of frozen processes using the `adb shell dumpsys activity`\n command and grep for `Apps frozen:`.\n\n- Check for the presence of the `/sys/fs/cgroup/uid_0/cgroup.freeze` file.\n\n- View logcat, which shows frozen and unfrozen entries each time a process\n migrates in or out of the freezer. For example:\n\n adb logcat | grep -i \"\\(freezing\\|froze\\)\""]]