android 杂记
2015-11-16 14:38
387 查看
android中可能有一些零散的东西,可能是常用也可能不是很常用,但是要用的却急的要命,下面记录了部分问题以及解决办法。
Q:android中软键盘弹出遮住webview输入框
A:
已经设置,接下里将mainfests中对应activity的主题theme改为下边即可
A:为什么会内存泄露?
Q:堆你村中的昌生命周期的对象持有短生命周期对象的强/软引用,尽管短生命周期的对象已经不再需要,但是因为长生命周期对象持有他的引用而导致不能被回收,最终导致内存泄露。下面是摘抄的一段放置内存溢出的一个雏形。
public class CacheBySoftRef {
// 首先定义一个HashMap,保存软引用对象。
private Map<String, SoftReference<Bitmap>> imageCache = new HashMap<String, SoftReference<Bitmap>>();
// 再来定义一个方法,保存Bitmap的软引用到HashMap。
public void addBitmapToCache(String path) {
// 强引用的Bitmap对象
Bitmap bitmap = BitmapFactory.decodeFile(path);
// 软引用的Bitmap对象
SoftReference<Bitmap> softBitmap = new SoftReference<Bitmap>(bitmap);
// 添加该对象到Map中使其缓存
imageCache.put(path, softBitmap);
}
// 获取的时候,可以通过SoftReference的get()方法得到Bitmap对象。
public Bitmap getBitmapByPath(String path) {
// 从缓存中取软引用的Bitmap对象
SoftReference<Bitmap> softBitmap = imageCache.get(path);
// 判断是否存在软引用
if (softBitmap == null) {
return null;
}
// 通过软引用取出Bitmap对象,如果由于内存不足Bitmap被回收,将取得空 ,如果未被回收,则可重复使用,提高速度。
Bitmap bitmap = softBitmap.get();
return bitmap;
}
}
Android应用开发过程中,为防止内存溢出,在处理一些暂用内存大而且生命周期较长对象的时候,可尽量应用软引用和弱引用计数。
Q:android中软键盘弹出遮住webview输入框
A:
android:windowSoftInputMode="stateVisible|adjustResize"
已经设置,接下里将mainfests中对应activity的主题theme改为下边即可
android:theme="@android:style/Theme.NoTitleBar"
A:为什么会内存泄露?
Q:堆你村中的昌生命周期的对象持有短生命周期对象的强/软引用,尽管短生命周期的对象已经不再需要,但是因为长生命周期对象持有他的引用而导致不能被回收,最终导致内存泄露。下面是摘抄的一段放置内存溢出的一个雏形。
public class CacheBySoftRef {
// 首先定义一个HashMap,保存软引用对象。
private Map<String, SoftReference<Bitmap>> imageCache = new HashMap<String, SoftReference<Bitmap>>();
// 再来定义一个方法,保存Bitmap的软引用到HashMap。
public void addBitmapToCache(String path) {
// 强引用的Bitmap对象
Bitmap bitmap = BitmapFactory.decodeFile(path);
// 软引用的Bitmap对象
SoftReference<Bitmap> softBitmap = new SoftReference<Bitmap>(bitmap);
// 添加该对象到Map中使其缓存
imageCache.put(path, softBitmap);
}
// 获取的时候,可以通过SoftReference的get()方法得到Bitmap对象。
public Bitmap getBitmapByPath(String path) {
// 从缓存中取软引用的Bitmap对象
SoftReference<Bitmap> softBitmap = imageCache.get(path);
// 判断是否存在软引用
if (softBitmap == null) {
return null;
}
// 通过软引用取出Bitmap对象,如果由于内存不足Bitmap被回收,将取得空 ,如果未被回收,则可重复使用,提高速度。
Bitmap bitmap = softBitmap.get();
return bitmap;
}
}
Android应用开发过程中,为防止内存溢出,在处理一些暂用内存大而且生命周期较长对象的时候,可尽量应用软引用和弱引用计数。
相关文章推荐
- android中handler用法总结
- Android学习方法-----心得
- 一些android笔记
- 说说Android应用的persistent属性
- Android超轻量下拉刷新、上拉加载更多控件,已完美适配ListView
- Android百度地图导航SDK2.0 定位SDK6.0.5的导航参数设置方法
- Android studio小技巧之xml与Java类快速跳转
- <android5.0>之共享元素
- Android日志打印与处理 UncaughtExceptionHandler 提交服务器
- Android中Bitmap和Drawable
- Android动画之属性动画(Property Animation)(二)
- ADB环境
- 自学android 碰到的知识点总结 (第二版)
- android layout_weight的使用注意点
- Android资源文件-drawable整理
- android线性布局
- Android开源github
- Android Dimming the System Bars 隐藏虚拟按键
- android 获取uri的正确文件路径的办法
- 如何让TabHost选项卡显示图片