Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Last active September 5, 2017 11:42
Show Gist options
  • Save ssaurel/8c1f6a36f311411b0e10824ffc9699f1 to your computer and use it in GitHub Desktop.
Save ssaurel/8c1f6a36f311411b0e10824ffc9699f1 to your computer and use it in GitHub Desktop.
Get Memory Info at Runtime on Android tutorial for the SSaurel's Blog
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txt = (TextView) findViewById(R.id.txt);
txt.setText(getMemoryInfo());
}
private String getMemoryInfo() {
MemoryInfo memoryInfo = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(memoryInfo);
Runtime runtime = Runtime.getRuntime();
String strMemInfo =
"Available Memory = " + memoryInfo.availMem + "\n"
+ "Total Memory = " + memoryInfo.totalMem + "\n"
+ "Runtime Max Memory = " + runtime.maxMemory() + "\n"
+ "Runtime Total Memory = " + runtime.totalMemory() + "\n"
+ "Runtime Free Memory = " + runtime.freeMemory() + "\n";
return strMemInfo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment