Published by Niharika AroraDeveloper Relations Engineer
The Android Operating system gives everyone the ability to access computing’s power. All users can see this vision, even those with entry-level smartphones that are subject to real limitations in terms of data storage and memory.
It was particularly important because we had just announced our first announcement. Android (Go Edition) In 2017, low-end devices accounted for 57% global smartphone shipments (IDC mobile phone tracker).
What does it mean? Android (Go edition)?
Android The mobile operating system (Go edition), is designed for smartphones starting at entry level with less RAM. Android The Go edition runs faster and uses less data. This allows Original Equipment Manufacturers to create affordable entry-level devices that give people the possibility of a better life. For more information, see the list below. Android (Go edition) device capability specifications, see this page on our site.
Most Recent Updates
Smartphones are continually being developed by us. Android (Go edition) more accessible with additional performance optimizations and features designed specifically for new & novice internet users, like translation, app switching, and data saving.
Here are some of the most recent changes we made to our website. Android 12:
Why should you build? Android (Go edition)?
With the fast growing & easily accessible internet, and all the features available at low cost, OEMs and developers are aiming & building their apps specifically for Android (Go edition) devices.
Fast forward to today — many people worldwide actively use an Android (Go edition) phone. Consider the big OEMs Like Jio Samsung, Oppo, Realme etc. Building Android (Go edition) devices, there is a need for developers to build apps that Perform well Particularly on the Go device.
The markets that have high levels of smartphone penetration and fast internet access can face challenges, like:
- It isn’t starting in the specified time.
- Your app’s size will increase if you add many required capabilities or features.
- What can you do to manage memory pressure when working with Go apps?
Optimize apps to maximize their effectiveness Android (Go edition)
To help your app succeed and deliver the best possible experience in developing markets, we have put together some best practices based on experience building our own Google apps Gboard & Camera from Google.
Approch
Optimize App Memory
- onTrimMemory can release cache-like memory(): TrimMemory() An app can use ActivityManager.getMyMemoryState(RunningAppProcessInfo) to reduce unnecessary memory. To best know an app’s current trim level, you can use ActivityManager.getMyMemoryState(RunningAppProcessInfo) and then try to optimize/trim the resources which are not needed.
GBoard utilized the onTrimMemory() It will signal that unneeded memory is being cut while the process runs in the background. This happens when there is not enough RAM to allow background processes to run properly. This helped to decrease the frequency of being low-memory killed, and also the average background RSS. Your app’s resident set size (RSS), is the memory that is occupied by it. It is not part of main memory, but is a subset. You can read more about RSS by clicking here.
- Check if malloc can be replaced with mmap when accessing read-only & large files: Mmap can only be used to read large files onto memory. There are some kernel optimizations that can be used to read-only memory mapped file files. These include unloading pages not being used.
This is often useful to load large assets and ML models.
- It is important to plan tasks that require the same resources (CPU, IIO, Memory) in a way that works well. Multiple memory-intensive operations could be running simultaneously, which can lead to overcrowding and a higher peak memory consumption. The Camera from Google app found multiple problems, ensured a cap to peak memory and further optimized their app by appropriately allocating resources, separating tasks into CPU intensive, low latency tasks(tasks that need to be finished fast for Good UX) & IO tasks. Tasks should be scheduled in the right thread pools/executors so that they run in balanced ways on limited resources.
- Find & fix memory leaks: Although it is hard to fight leaks, there are some tools that can help. Android Studio Memory Profiler/Perfetto are specifically made to help you find and fix memory problems quickly.
Google apps made use of tools to detect and correct memory issues, which allowed for a lower memory footprint. This allowed the other parts of the app run with no additional memory stress.
This article is about Take this example From Gboard App is about See leaks
Caching subviews like this is one example.
It is possible that the [keyboardView] will be released in the future. To prevent the view from leaking, it would be a good idea to assign the null value for the keyButtonA at this time.|keyboardView| might be released at some time, and the |keyButtonA| should be assigned as null appropriately at some time to avoid the view leak.
Lessons learned:
- After analysing and validating the impacts, it is important to update frameworks/library regularly.
- Be sure to free memory before you allocate new values to pointers pointing at other objects in Java heap. (native backend java objects)
You can take this example as an illustration:
It should be possible to do this in Java
This issue should be resolved by GC.
If KlassA The system allocates resources natively below, and it doesn’t automatically cleanup. finalize(..) Caller must call to make this happen release(..) It should look like this:
It will happen otherwise Leakage Memory from the native heap
- Optimize bitmaps Apps that have large images/drawables tend to use more memory. Google apps have optimized large bitmaps used within their apps.
Lessons learned :
- You prefer lazy/on-demand initializations for large drawables.
- When necessary, release view
- If possible, don’t use full-color bitmaps.
Here’s an example: Gboard’s glide typing feature needs to show an overlay view with a bitmap of trails, which can only has the alpha channel and apply a color filter for rendering.
Gboard: A screen shot of glide typing
- Make sure to only adjust the alpha channel of the bitmap in complex views. It saved them several MBs, per screen size/density.
- Glide can be used to:
- ARGB_8888 has 4 bytes/pixel while RGB_565 consumes 2 bytes/pixel. While the memory footprint is reduced to half when RGB_565 formats are used, it has a lower bitmap quality which comes at a higher price. You can adapt your case to meet alpha needs, regardless of whether you require them.
- Configure and use cache wisely when using a 3P lib like Glide for image rendering.
- When building an app, consider other GIF options Android (Go edition) as GIFs take a lot of memory.
- The aapt Tool can optimize image resources that are stored in res/drawable/ during build. It also supports lossless compression. Aapt tools can, for instance, convert true-color PNGs that do not contain more than 256 colours to an 8 bit PNG with a colour palette. The result is an image that has equal quality and a smaller memory footprint. Learn more.
- PNG files can be reduced without having to compromise image quality with tools such as pngcrush and pngquant. All these tools allow you to reduce PNG file sizes while still maintaining the high quality image.
- Resizable bitmaps are also available. Draw 9-patch is an editor that supports WYSIWYG. Android Studio lets you create bitmap images, which are automatically resized to suit the content of your view and the screen size. You can learn more about it here.
Recap
This blog discusses why developers should build for. Android (Go edition), a standard approach to follow while optimizing their apps and some recommendations & learnings from Google apps to improve their app memory and appropriately allocate resources.
This blog’s next section will focus on Startup latency, app sizes, and Google apps tools that help identify and resolve performance issues.