Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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