Android ActivityManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ActivityManager class.

This code example shows how to use the following methods:getMemoryInfo
        } 
 
        ActivityManager am = (ActivityManager)
                        context.getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(outInfo);
 
        return outInfo.lowMemory;
    } 
 
    // FIXME: need to optimize this method. 
    private static boolean isLowMemory(SQLiteException e) {
        return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE);
    } 
 
    public static void checkSQLiteException(Context context, SQLiteException e) {
        if (isLowMemory(e)) {
            Toast.makeText(context, com.android.internal.R.string.low_memory,
                    Toast.LENGTH_SHORT).show();
        } else { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getRunningTasks
     * @param context 
     * @return true if another application is above this one. 
     */ 
    public static boolean isApplicationBroughtToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true; 
            } 
        } 
 
        return false; 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMemoryInfo
     
    @Test 
    public void canGetMemoryInfoEvenWhenWeDidNotSetIt() { 
        ActivityManager activityManager = (ActivityManager) Robolectric.application.getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo fetchedMemoryInfo = new ActivityManager.MemoryInfo();
        activityManager.getMemoryInfo(fetchedMemoryInfo);
        assertFalse(fetchedMemoryInfo.lowMemory);
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getRunningTasks
     */ 
    static void handleApplicationClosing(final Context context, int keyCode) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            ActivityManager am = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningTaskInfo> tasks = am.getRunningTasks(2);
 
            RunningTaskInfo currentTask = tasks.get(0);
            RunningTaskInfo nextTask = tasks.get(1);
 
            // if we're looking at this application's base/launcher Activity, 
            // and the next task is the Android home screen, then we know we're 
            // about to close the app 
            if (currentTask.topActivity.equals(currentTask.baseActivity)
                    && nextTask.baseActivity.getPackageName().startsWith("com.android.launcher")) {
                DroidFuApplication application = (DroidFuApplication) context
                        .getApplicationContext();
                application.onClose();
            } 
        } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDeviceConfigurationInfo
    } 
 
    private boolean detectOpenGLES20() { 
        ActivityManager am =
            (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        return (info.reqGlEsVersion >= 0x20000);
    } 
 
    @Override 
    protected void onResume() { 
        // Ideally a game should implement onResume() and onPause() 
        // to take appropriate action when the activity looses focus 
        super.onResume(); 
        mGLSurfaceView.onResume();
    } 
 
    @Override 
    protected void onPause() { 
        // Ideally a game should implement onResume() and onPause() 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMemoryClass
   * result is used for the lifetime of the game. 
   */ 
  protected Bitmap.Config preferredBitmapConfig() {
    ActivityManager activityManager = (ActivityManager)
      getApplication().getSystemService(Context.ACTIVITY_SERVICE);
    int memoryClass = activityManager.getMemoryClass();
    int format = getWindowManager().getDefaultDisplay().getPixelFormat();
    // for low memory devices (like the HTC Magic), prefer 16-bit bitmaps 
    return (format == PixelFormat.RGBA_4444 || memoryClass <= 16) ?
      Bitmap.Config.ARGB_4444 : Bitmap.Config.ARGB_8888;
  } 
 
  protected float scaleFactor() { 
    return 1; // TODO: determine scale factor automatically? 
  } 
 
  /** Configures the maximum simultaneous sounds that may be played back. */ 
  protected int maxSimultaneousSounds() { 
    return 8; 
  } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMemoryInfo
        } 
 
        ActivityManager am = (ActivityManager)
                        context.getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(outInfo);
 
        return outInfo.lowMemory;
    } 
 
    // FIXME: need to optimize this method. 
    private static boolean isLowMemory(SQLiteException e) {
        return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE);
    } 
 
    public static void checkSQLiteException(Context context, SQLiteException e) {
        if (isLowMemory(e)) {
            Toast.makeText(context, com.android.internal.R.string.low_memory,
                    Toast.LENGTH_SHORT).show();
        } else { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDeviceConfigurationInfo
	  
	 private boolean detectOpenGLES20()  
	 { 
	     ActivityManager am =
	            (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
	     ConfigurationInfo info = am.getDeviceConfigurationInfo();
	     return (info.reqGlEsVersion >= 0x20000);
	 } 
	 
     static { 
         System.loadLibrary("game");
     } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMemoryInfo
     
    @Test 
    public void canGetMemoryInfoEvenWhenWeDidNotSetIt() { 
        ActivityManager activityManager = (ActivityManager) Robolectric.application.getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo fetchedMemoryInfo = new ActivityManager.MemoryInfo();
        activityManager.getMemoryInfo(fetchedMemoryInfo);
        assertFalse(fetchedMemoryInfo.lowMemory);
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLauncherLargeIconDensity

Related Android ActivityManager Questions & Answers:

See Code Examples for Android ActivityManager Methods: