Android(Go 版本)开发的最佳实践
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
开始针对 Android(Go 版本)开发或优化应用时,请遵循以下最佳实践和常见问题解答。
针对 Go 进行优化或者进行全新开发
许多想要在 Android Go 上发布应用的开发者可能都想知道,是应该优化其现有应用,还是应该开发全新的应用。这一选择取决于许多因素,包括您拥有多少开发资源、您是否能够在应用中保留针对这些设备进行了优化的功能,以及您希望为世界各地的最终用户提供何种分发场景。
- 为所有设备提供相同的应用
- 为 Android(Go 版本)设备和所有其他设备使用相同的应用,并提供一致的体验。在这种情况下,您需要优化现有应用,使其能够在这些设备上良好地运行,并使现有用户从这些优化中获得性能提升。强烈建议您使用 Android App Bundle 来大幅缩减应用大小,而不必重构代码。
- 两种应用
- 针对 Android(Go 版本)设备开发一个新的“精简版”应用。您可以保留现有应用。“精简版”应用仍然可以面向所有语言区域的所有设备提供,因为并不要求此“精简版”应用仅面向 Android(Go 版本)设备。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Best practices for Android (Go edition) development\n\nFollow these best practices and answers to common questions when starting to\ndevelop or optimize your app for Android (Go edition).\n\n- Don't add any excessive permissions to your app.\n- Minimize app activity when in the background and when the device is running on low power.\n- Avoid using wake locks because they prevent the device from going into low-power states.\n- Batch network activity to reduce the number of wakeups. You can use [WorkManager](/topic/libraries/architecture/workmanager) to schedule tasks and let the system batch operations.\n- Validate that your layouts scale down by testing on smaller screens.\n- Methods such as [`isLowRamDevice()`](/reference/android/app/ActivityManager#isLowRamDevice()) and [`getMemoryClass()`](/reference/android/app/ActivityManager#getMemoryClass()) help determine memory constraints at runtime. Using this information, you can scale down your memory use. For example, you can use lower resolution images on low memory devices.\n- Allow your app to be installed to external storage using the [`android:installLocation`](/guide/topics/manifest/manifest-element#install) flag in your `AndroidManifest.xml` file.\n- If you're looking to build for a larger-scaled audience, take a look at the [Build for billions](/topic/billions) documentation.\n\nOptimize for Go or start fresh\n------------------------------\n\nMany developers looking to launch apps on Android Go may wonder if they should\noptimize their existing app or develop an entirely new one. This choice depends\non many factors, including how many development resources you have, whether or\nnot you can keep features in your app that are optimized for these devices,\nand what type of distribution scenarios you want to enable for end-users around\nthe world.\n\nOne app for all\n: Use the same app for Android (Go edition) devices and all other devices with\n an identical experience. In this case, you are optimizing your existing app to\n run well on these devices, and your existing users gain performance benefits\n from those optimizations. We highly encourage you to use the\n [Android App Bundle](/guide/app-bundle) to experience significant size savings\n without having to refactor your code.\n\nTwo apps\n: Create a new \"light\" app and target Android (Go edition) devices.\n You can leave your existing app as is. The \"lite\" app can still target all\n devices in all locales as there is no requirement for this \"lite\" app to only\n target Android (Go edition) devices."]]