android getMemoryClass()的使用
来源:互联网 发布:中国需要几艘航母 知乎 编辑:程序博客网 时间:2024/06/05 15:23
getMemoryClass()的使用,之前看到这个,不知道有什么作用,后来在网上查找资料,明白用途了。
Android基本概念: 应用, 任务, 进程, 和线程
开始我们的ActivityManager学习吧!
ActivityManager的内部类:
ActivityManager.MemoryInfo : 系统内存使用情况的信息 ,可以通过getMemoryInfo(ActivityManager.MemoryInfo)
. 来获得该类对象
ActivityManager.ProcessErrorStateInfo: 错误状态的进程
ActivityManager.RecentTaskInfo:近期用户打开的任务信息
ActivityManager.RunningAppProcessInfo: 正在运行的应用程序进程
ActivityManager.RunningServiceInfo: 正在运行的服务信息
ActivityManager.RunningTaskInfo: 正在运行的任务信息
ActivityManager类对象的获取:
ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager类中的方法:
public int getLargeMemoryClass ()说明: 如果在AndroidManifest.xml中的<application >标签下将属性android:largeHeap=“true”
这个属性决定你的应用进程是否应当在更大的Dalvik堆中创建,为了在运行时查看可用内存,
可用getLargeMemoryClass()或者 getMemoryClass()
通过代码查看每个进程可用的最大内存,即heapgrowthlimit值:
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int memClass = activityManager.getMemoryClass();//64,以m为单位
注意:在设置了heapgrowthlimit的情况下,单个进程可用最大内存为heapgrowthlimit值。在android开发中,如果要使用大堆,需要在manifest中指定android:largeHeap为true,这样dvm heap最大可达heapsize。
其实就是查询手机对于app的最大使用内存,这个可以判断手机的性能,从而确定自己的app该注重性能还是注重内存的使用。
android getMemoryClass()的使用就讲完了、
就这么简单。
- android getMemoryClass()的使用
- 《Android5.1源码探究 —— ActivityManager(2):getMemoryClass()及getLargeMemoryClass()》
- 【Android】Android对话框的使用
- 【Android】android Fragment的使用
- Android TabHost的使用
- Android Logcat的使用
- Android ArrayAdapter的使用
- android ndk的使用
- android keystore的使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android-Notification的使用
- Android TabHost的使用
- Android GridView的使用
- Android Menu的使用
- Android的SDcard使用
- android ListView的使用
- Android WebView的使用
- spring同父接口下装配不同bean的解决方案
- 增量式记录QT学习
- Tomcat的Https设置及Http自动跳转Https
- Linux内核模块配置文件
- c#常用的类和方法
- android getMemoryClass()的使用
- vlc流程
- 关于lstm和gru的一些简单资料,讲得比较容易理解
- 关于recyclerView水平滑动和垂直滑动时的崩溃问题
- jQuery<3.2>
- Kubernetes1.6新特性:POD高级调度-POD调度器配置变化
- 多线程实现生产者与消费者模式
- iOS数组相关问题
- [NodeJS]创建HTTP、HTTPS服务器与客户端