Android Context Get getApplicationMemoryClass(@Nonnull Context context)

Here you can find the source of getApplicationMemoryClass(@Nonnull Context context)

Description

Returns the upper memory usage limit in bytes for the current application retrieved from ActivityManager#getMemoryClass() .

License

Apache License

Parameter

Parameter Description
context The Context to retrieve the ActivityManager

Return

The application memory class in bytes

Declaration

public static int getApplicationMemoryClass(@Nonnull Context context) 

Method Source Code

//package com.java2s;
/*/*  w w w  . j  a  v  a 2  s . c om*/
 * Copyright 2013 Luluvise Ltd
 * Copyright 2013 Marco Salis - fast3r(at)gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.annotation.Nonnull;

import android.app.ActivityManager;

import android.content.Context;

public class Main {
    /**
     * Returns the upper memory usage limit in bytes for the current application
     * retrieved from {@link ActivityManager#getMemoryClass()}. Using a
     * percentage of this value is a reliable way to limit memory caches.
     * 
     * @param context
     *            The {@link Context} to retrieve the {@link ActivityManager}
     * @return The application memory class in bytes
     */
    public static int getApplicationMemoryClass(@Nonnull Context context) {
        final ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        return manager.getMemoryClass() * 1024 * 1024; // to bytes
    }
}

Related

  1. getAnimId(Context paramContext, String paramString)
  2. getApp(Context ctx, String packageName)
  3. getAppKey(Context context)
  4. getAppVersion(Context context)
  5. getApplicationInfos(Context context)
  6. getApplicationMetaData(Context context, String key)
  7. getApplicationName(Context ctx)
  8. getAsset(@Nonnull Context context, @Nonnull String path)
  9. getAsset(@Nonnull Context context, @Nonnull String path)