In that tutorial, you are going to discover how to get Memory Information concerning a smartphone or tablet on Android.
In an Android application, you can get information concerning :
- The available memory on the system
- The total memory accessible by the kernel
- The maximum number of bytes the heap can expand to
- The current number of bytes taken by the heap
- The current number of those bytes actually used by live objects
These information can be retrieved via two objects of the Android Standard SDK : MemoryInfo and Runtime.
Note that you can discover this tutorial in video on YouTube :
First, we need to create a simple user interface to display the memory information on the screen. This UI will consist of a TextView centered on the main layout.
Get the Memory Info
Now, we can write the Java code of the Main Activity to get Memory Information. First, we create a MemoryInfo object in which we load the memory information by calling the getMemoryInfo method of the ActivityManager system service.
Then, we get the instance of the Runtime object by calling the getRuntime method of the Runtime object. Last step is just to format all these information and return that to display them on the screen.
That gives us the following code :
By running the application, we can enjoy the memory information displayed on the screen :
That’s all for that tutorial. To discover more tutorials on Android Development, don’t hesitate to subscribe to the SSaurel’s Channel.
This channel will offer you tutorials on Android, Web Development and some others programming tips. Demo video of…
You can also visit the SSaurel’s Blog : https://www.ssaurel.com/blog