Last active
September 5, 2017 11:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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