启用机器人:largeHeap在安卓4.0,而在Android 2.3的禁用 [英] Enable android:largeHeap in Android 4, and disable it in Android 2.3
问题描述
目前,我有一张code,其目的是在Android 2.3的同时运行4 +
Currently, I have a piece of code, which is designed to run both in Android 2.3 and 4+
在code将执行更好(如果它不会出现内存不足的异常大部分的时间),如果安卓largeHeap
正在在AndroidManifest.xml中应用
The code will perform much better (Where it will not have OutOfMemory exception most of the time), if android:largeHeap
is being applied in AndroidManifest.xml.
<application
android:name=".MyApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="nosensor"
android:largeHeap="true"
目前,我的安卓的minSdkVersion
需要设置为15,而不是10(Android 2.3的)。如果不是,机器人:largeHeap
是不允许在AndroidManifest.xml中
Currently, my android:minSdkVersion
need to set to 15 instead of 10 (Android 2.3). If not, android:largeHeap
is not allowable in AndroidManifest.xml.
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
在单个APK,怎么可能,我可以设置
- 使用
安卓largeHeap
的选择,如果我在安卓4.0 + - 请不要使用
安卓largeHeap
的选择,如果我在的Android 2.3
- Use
android:largeHeap
option if I were in Android 4+ - Do not use
android:largeHeap
option if I were in Android 2.3
推荐答案
您还可以禁用大型堆在蜂窝,并使其在ICS或JB。只是有点哈克什么的。下面是我试过了。
You can also disable large heap in Honeycomb and enable it in ICS or JB. Just a little hacky or something. Here's what I tried.
在我们开始之前,改变你的构建目标蜂窝,果冻豆或ICS,所以我们可以把安卓largeHeap
属性。此外,您还可以设置安卓的minSdkVersion
到 API 10
。
Before we proceed, change your Build target to Honeycomb, Jelly Bean or ICS so we can put android:largeHeap
attribute. Also, you can set android:minSdkVersion
to API 10
.
Android的 API 10
不支持大的堆。
Android API 10
doesn't support large heap.
- 创建于
资源文件夹
文件夹值-V14
- 我在
值-V14创建
bools.xml
- 将在
bools.xml
此值值-V14的
- Create a folder
values-v14
inres
folder - I created
bools.xml
invalues-v14
- Put this value in
bools.xml
ofvalues-v14
&LT;布尔名=largeheap&GT;真&LT; /布尔&GT;
布尔值> bools.xml
或值时─[API版本]
> bools.xml
来禁用大型堆在不同的API版本或默认。
boolean value for values
> bools.xml
or values-[API VERSION]
> bools.xml
to disable large-heap in different API Version or by default.
<bool name="largeheap">false</bool>
修改的价值机器人:largeHeap
到 @布尔/ largeheap
而不是硬codeD 真
或假
Change the value of android:largeHeap
to @bool/largeheap
instead of hardcoded true
or false
<application
android:largeHeap="@bool/largeheap"
android:allowBackup="true"
android:icon="@drawable/ic_launcher">
....
</application>
我通过一个内存泄漏应用程序或只是加载了巨大的位图和,其工作测试了这个code!
I tested this code by making a memory leak application or just load a Huge bitmaps, and, its working!
祝您好运!
这篇关于启用机器人:largeHeap在安卓4.0,而在Android 2.3的禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!