安卓检查内存demo一例
来源:互联网 发布:dtmb软件下载 编辑:程序博客网 时间:2024/06/17 08:56
源代码如下:
package me.normalhh.checkmemory;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.TextView;/** * 这个app主要用于检查手机的内存 * * @author Normal */public class MyActivity extends Activity implements View.OnClickListener { private TextView tv1; private Button maxMemory, freeMemory, totalMemory; private long maxMemoryint, freeMemoryint, totalMemoryint; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv1 = (TextView) findViewById(R.id.tv1); maxMemory = (Button) findViewById(R.id.maxMemory); freeMemory = (Button) findViewById(R.id.freeMemory); totalMemory = (Button) findViewById(R.id.totalMemory); maxMemory.setOnClickListener(this); freeMemory.setOnClickListener(this); totalMemory.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.maxMemory: checkMemory(); Log.i("maxMemory", "maxMemory:" + maxMemoryint); tv1.setText("程序总内存:" + maxMemoryint); break; case R.id.freeMemory: checkMemory(); Log.i("freeMemory", "freeMemory:" + freeMemoryint); tv1.setText("程序剩余内存:" + freeMemoryint); break; case R.id.totalMemory: checkMemory(); Log.i("totalMemory", "totalMemory:" + totalMemoryint); tv1.setText("程序已使用内存:" + totalMemoryint); break; } } /** * 查看内存使用情况 * * @return */ public void checkMemory() { //程序总内存 maxMemoryint = Runtime.getRuntime().maxMemory(); //已经从系统拿出来但是没有使用的内存 freeMemoryint = Runtime.getRuntime().freeMemory(); //已经使用的总内存 totalMemoryint = Runtime.getRuntime().totalMemory(); }}
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent"><TextViewandroid:id = "@+id/tv1"android:layout_width = "fill_parent"android:layout_height = "wrap_content"android:text = "123456789"android:textSize = "20sp"android:textColor = "@android:color/holo_red_light"/><Buttonandroid:id = "@+id/maxMemory"android:layout_width = "wrap_content"android:layout_height = "wrap_content"android:text = "@string/maxMemory"/><Buttonandroid:id = "@+id/freeMemory"android:layout_width = "wrap_content"android:layout_height = "wrap_content"android:text = "@string/freeMemory"/><Buttonandroid:id = "@+id/totalMemory"android:layout_width = "wrap_content"android:layout_height = "wrap_content"android:text = "@string/totalMemory"/></LinearLayout>
- 安卓检查内存demo一例
- 安卓OOM 内存溢出的一
- 安卓实时弹幕demo(一)弹幕效果
- 安卓实时弹幕demo(一)弹幕效果
- 指南针安卓demo
- 安卓定位Demo
- 安卓 闹钟demo
- 安卓的demo
- 安卓指纹识别demo
- 安卓指纹识别demo
- 极光推送---安卓Demo
- 安卓jni开发demo
- 安卓静态代码检查工具比较
- 安卓检查网络状态及WIFI
- 安卓程序监听崩溃检查
- 安卓去除apk的签名检查
- 安卓内存
- 安卓内存问题
- MS100题第一题
- sublime text2中gbk转换为utf-8
- 如何解决跨站点请求伪造
- document.all 在各浏览器中的支持不同
- jquery validate remote 返回错误
- 安卓检查内存demo一例
- spring中context:property-placeholder元素
- sizeof和strlen的区别
- 编译时常出现缺少库的问题以及解决方案
- 我的android 第10天 - pull解析Xml文档
- Cryengine渲染引擎剖析
- oracle_Grid Infrastructure 启动的五大问题
- js控制input框只读
- OCP-1Z0-053-V13.02-232题