当前位置: 编程技术>移动开发
本页文章导读:
▪什么时候应当用onSaveInstanceState或者是onPause来保存状态 什么时候应该用onSaveInstanceState或者是onPause来保存状态?
引用Basic rule to follow - use onSaveInstanceState if you want to put data into a bundle to be by onCreate. Use onPause to write persistent data that can be read during onRes.........
▪ 关键字查询 关键字查询 。
tcp.stream eq 4
......
▪ 使用bitmap缩略图,解决图片大小超过预算的VM的有关问题 使用bitmap缩略图,解决图片大小超过预算的VM的问题
Android 2.3.3
Eclipse Version: 3.7.0
LogCat
Activity中显示大图,部分源代码如下:
try {
bitmap = BitmapFactory.decodeFile("/" + nokia.getBit.........
[1]什么时候应当用onSaveInstanceState或者是onPause来保存状态
来源: 互联网 发布时间: 2014-02-18
什么时候应该用onSaveInstanceState或者是onPause来保存状态?
引用
Basic rule to follow - use onSaveInstanceState if you want to put data into a bundle to be by onCreate. Use onPause to write persistent data that can be read during onResume.
In your case you will probably want to put most of your suspend logic in onPause. I find that I almost always use onPause for most suspend logic since my apps (games) don't usually reduce to something that can fit into a bundle easily.
In your case you will probably want to put most of your suspend logic in onPause. I find that I almost always use onPause for most suspend logic since my apps (games) don't usually reduce to something that can fit into a bundle easily.
[2] 关键字查询
来源: 互联网 发布时间: 2014-02-18
关键字查询 。
tcp.stream eq 4
tcp.stream eq 4
[3] 使用bitmap缩略图,解决图片大小超过预算的VM的有关问题
来源: 互联网 发布时间: 2014-02-18
使用bitmap缩略图,解决图片大小超过预算的VM的问题
Android 2.3.3 Eclipse Version: 3.7.0 LogCat
Activity中显示大图,部分源代码如下:
try { bitmap = BitmapFactory.decodeFile("/" + nokia.getBitmap(), opt); } catch (Exception e) { e.printStackTrace(); } nokiaImage.setImageBitmap(bitmap);
使用过程中
LogCat 报错信息:
02-07 13:14:22.947: DEBUG/dalvikvm(33246): GC_EXTERNAL_ALLOC freed 75K, 61% free 3080K/7751K, external 14227K/16275K, paused 100ms 02-07 13:14:23.017: ERROR/dalvikvm-heap(33246): 4147200-byte external allocation too large for this process. 02-07 13:14:23.137: ERROR/GraphicsJNI(33246): VM won't let us allocate 4147200 bytes 02-07 13:14:23.148: DEBUG/dalvikvm(33246): GC_FOR_MALLOC freed 2K, 61% free 3078K/7751K, external 14227K/16275K, paused 37ms 02-07 13:14:23.191: DEBUG/skia(33246): --- decoder->decode returned false 02-07 13:14:23.191: DEBUG/AndroidRuntime(33246): Shutting down VM 02-07 13:14:23.191: WARN/dalvikvm(33246): threadid=1: thread exiting with uncaught exception (group=0x40015560) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): FATAL EXCEPTION: main 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at com.tmall.nokia.Book.handerUI(Book.java:522) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at com.tmall.nokia.Book$1.run(Book.java:396) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.os.Handler.handleCallback(Handler.java:587) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.os.Handler.dispatchMessage(Handler.java:92) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.os.Looper.loop(Looper.java:123) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at android.app.ActivityThread.main(ActivityThread.java:3683) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at java.lang.reflect.Method.invokeNative(Native Method) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at java.lang.reflect.Method.invoke(Method.java:507) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-07 13:14:23.218: ERROR/AndroidRuntime(33246): at dalvik.system.NativeStart.main(Native Method) 02-07 13:14:23.268: WARN/ActivityManager(61): Force finishing activity com.tmall.nokia/.Book
发生错误的原因分析:
主要是bitmap图片尺寸较大,使用时超过预算的VM;
网上有两种解决办法:
一种是增加VM大小
VMRuntime.getRuntime().setMinimumHeapSize(12 * 1024 * 1024); VMRuntime.getRuntime().setTargetHeapUtilization(0.85f);
经个人测试无效;
另一种是使用缩略图,缩小图片的尺寸大小
//图片缩小倍数 opt.inSampleSize = 2;
可以实现。
最新技术文章: