APIs

Android defines several APIs you can use to learn about how much memory is available on the system and how much is being used:

  • ActivityManager'sgetMemoryInfo()
  • ActivityManager'sgetMemoryClass()
  • ActivityManager'sgetLargeMemoryClass()
  • Debug's dumpHprofData()
  • Debug's getMemoryInfo()
  • Debug's getNativeHeapAllocatedSize()
  • Debug's getNativeHeapSize()

TIP: Set android:largeHeap to true in your application's manifest file to use a large heap. This attribute was introduced in Android 3.0. Note that there is no guarantee the large heap is any larger than the regular heap. You should try hard to prevent your application from having to depend on this setting.

Listing 4–21 shows how to use the two getMemoryInfo() methods.

Listing 4–21. Calling getMemoryInfo()

    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(memInfo);
    // use information from memInfo here...
    
    Debug.MemoryInfo debugMemInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(debugMemInfo);
    // use information from debugMemInfo here...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.255.140