Class MemoryInformation



  • public class MemoryInformation
    extends java.lang.Object
    This class is used to get information about the physical memory (RAM) that is available on the device
    • Constructor Summary

      Constructors 
      Constructor and Description
      MemoryInformation(Context context)
      Creates and initialises a MemoryInformation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String formatMemoryUsage()
      Formats the current memory usage of the device in megabytes
      int getTotalMemory()
      Gets the total memory in megabytes that this device has.
      int getTotalMemoryApi()
      Gets the total memory that this device has from the Android APIs directly.
      int getTotalMemoryCompat()
      Gets the total memory that this device has by reading /proc/meminfo
      int getUsedMemory()
      Returns the used memory in megabytes
      boolean isLowMemory()
      Determines whether the device is currently experiencing a low memory warning.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MemoryInformation

        public MemoryInformation(Context context)
        Creates and initialises a MemoryInformation.

        This will also call MemoryInformation.getTotalMemory() to initialise the class.

        Parameters:
        context - A context, used to query the system for memory information.
    • Method Detail

      • formatMemoryUsage

        public java.lang.String formatMemoryUsage()
        Formats the current memory usage of the device in megabytes

        The display will look like the following.

        300MB / 512MB

        The formula used is (total - available) / total, i.e 300 is (total - available) and 512 is (total).

        Returns:
        the formatted memory usage
      • getUsedMemory

        public int getUsedMemory()
        Returns the used memory in megabytes
        Returns:
        the used memory in megabytes
      • getTotalMemory

        public int getTotalMemory()
        Gets the total memory in megabytes that this device has.

        This version will automatically pick the best way of determining the total amount of memory depending on what Android API level the device is running on. If the API level is 17 or later the memory is read directly from the MemoryInfo API.

        If the API level is lower than 17 then the memory will be determined by examining the /proc/meminfo file.

        Returns:
        The total memory in megabytes
      • getTotalMemoryCompat

        public int getTotalMemoryCompat()
        Gets the total memory that this device has by reading /proc/meminfo

        Prefer the user of getTotalMemory() because this will select the best method of determining the total amount of memory.

        Returns:
        the total memory in megabytes
      • getTotalMemoryApi

        public int getTotalMemoryApi()
        Gets the total memory that this device has from the Android APIs directly.

        Prefer the user of getTotalMemory() because this will select the best method of determining the total amount of memory.

        Returns:
        the total memory in megabytes
      • isLowMemory

        public boolean isLowMemory()
        Determines whether the device is currently experiencing a low memory warning.
        Returns:
        true if this device is experiencing a low memory warning at this instant, false otherwise.