【问题标题】:how increase memory for application如何增加应用程序的内存
【发布时间】:2013-09-09 04:18:32
【问题描述】:

如何为应用增加内存?

E/GraphicsJNI(305): VM won't let us allocate 5529600 bytes

我有这个错误,我正在尝试应用

largeHeap="true"

但我收到一个错误:

error: No resource identifier found for attribute 'largeHeap' in package 'android'

我的代码:

public class FourthActivity extends Activity {
    ImageView fotik , cig, zajigalka, fotki, btn, string, flash, telefon;
    Animation textfade, buttonfade, fotikfade, sright, sdown, fl, stringfade, fotofade;

Timer t1, t2, t3, t4,t5;
public RelativeLayout lay;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.fourthlayout);

    ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this);
    lay = (RelativeLayout)this.findViewById(R.id.lay);
    lay.setOnTouchListener(activitySwipeDetector);

    fotik=(ImageView)findViewById(R.id.imageView1);
    fotki=(ImageView)findViewById(R.id.imageView2);
    flash=(ImageView)findViewById(R.id.imageView8);
    string=(ImageView)findViewById(R.id.imageView7);
    telefon=(ImageView)findViewById(R.id.imageView3);
    cig=(ImageView)findViewById(R.id.imageView4);
    zajigalka=(ImageView)findViewById(R.id.imageView6);     
    btn=(ImageView)findViewById(R.id.imageView5);           

    fotki.setVisibility(View.INVISIBLE);
    flash.setVisibility(View.INVISIBLE);
    string.setVisibility(View.INVISIBLE);
    btn.setVisibility(View.INVISIBLE);

    fotikfade=AnimationUtils.loadAnimation(this, R.anim.lay4translatefotik);
    fotofade=AnimationUtils.loadAnimation(this, R.anim.text_fadein_pop);
    fl=AnimationUtils.loadAnimation(this, R.anim.lay2scale);


     sright = AnimationUtils.loadAnimation(this, R.anim.lay2move_rotate_right);
     sdown = AnimationUtils.loadAnimation(this, R.anim.lay17translatepack);

     cig.startAnimation(sdown);
     zajigalka.startAnimation(sright);
     telefon.startAnimation(fotofade);
     fotik.setVisibility(View.INVISIBLE);


     fotik.startAnimation(fotikfade);
        fotik.setVisibility(View.VISIBLE);

        t2 = new Timer();
        t2.schedule(new TimerTask() {          
            @Override
            public void run() {
                TimerMethod2();} },  900);

}
protected void onStop(){
    super.onDestroy();      
    }

private void TimerMethod2()
{
    this.runOnUiThread(Timer_Tick2);
}
private Runnable Timer_Tick2 = new Runnable() {
    public void run() {

        t1 = new Timer();
        t1.schedule(new TimerTask() {          
            @Override
            public void run() {
                TimerMethod();} },  900);
        t5 = new Timer();
        t5.schedule(new TimerTask() {          
            @Override
            public void run() {
                TimerMethod5();} },  700);

    }
}; 

private void TimerMethod()
{
    this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable() {
    public void run() {

        fotki.setVisibility(View.VISIBLE);
         fotki.startAnimation(fotofade);
         string.setVisibility(View.VISIBLE);
         string.startAnimation(fotofade);
         btn.setVisibility(View.VISIBLE);
    }
}; 
private void TimerMethod5()
{
    this.runOnUiThread(Timer_Tick5);
}
private Runnable Timer_Tick5 = new Runnable() {
    public void run() {
         flash.startAnimation(fl);

    }
};
public void onClick(View v)
{
    Intent intent=new Intent(FourthActivity.this, FifthActivity.class);

      startActivity(intent);    
      onStop();

}
public class ActivitySwipeDetector implements View.OnTouchListener {

    static final String logTag = "ActivitySwipeDetector";
    private Activity activity;
    static final int MIN_DISTANCE = 100;
    private float downX, downY, upX, upY;

    public ActivitySwipeDetector(Activity activity){
        this.activity = activity;
    }

    public void onRightToLeftSwipe(){
        Intent intent=new Intent(FourthActivity.this, FifthActivity.class);
        startActivity(intent);
        onStop();
    }

    public void onLeftToRightSwipe()
    {
        Intent intent=new Intent(FourthActivity.this, ThirdActivity.class);
        startActivity(intent);
        onStop();
    }

    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()){
            case MotionEvent.ACTION_DOWN: {
                downX = event.getX();
                downY = event.getY();
                return true;
            }
            case MotionEvent.ACTION_UP: {
                upX = event.getX();
                upY = event.getY();

                float deltaX = downX - upX;
                float deltaY = downY - upY;

                if(Math.abs(deltaX) > MIN_DISTANCE){
                    if(deltaX < 0) { this.onLeftToRightSwipe(); return true; }
                    if(deltaX > 0) { this.onRightToLeftSwipe(); return true; }
                }
                else {
                        Log.i(logTag, "Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE);
                        return false; 
                }


                return true;
            }
        }
        return false;
    }

    }

}

【问题讨论】:

  • API level 13以后,如果我没记错的话可以加android:largeHeap:"true"

标签: android memory memory-management android-largeheap


【解决方案1】:

您是否在清单中将&lt;application android:largeHeap="true" ...&gt; 定义为应用程序的属性? 至少,您应该使用 Honeycomb 作为 ths 属性。

看看这个帖子:https://stackoverflow.com/a/11275719/411951

【讨论】:

  • 我尝试将其定义为应用程序和活动结果相同
  • 您使用哪个 API 级别?
  • 我使用 min 7 和目标版本 8
  • 据我所知,您应该至少对属性 largeHeap 使用蜂窝(API Lvl 11)
  • 并非如此。内存应该足以完成正常任务。对于像图像这样的文件,谷歌文档中有一个关于图像缓存的很好的教程。为什么要使用 largeHeap 属性?通常的方法是提高应用程序的内存使用率,因此您不需要启用此属性
【解决方案2】:

在您的清单中将此代码写入应用程序标记中

<application android:icon="@drawable/icon" 
 android:label="@string/app_name" 
 android:largeHeap="true">

largeHeap 属性只出现在 API 11 或更高版本之后

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

在您的清单中使用此代码将您的目标设置为 API 19

希望对你有帮助

【讨论】:

  • 为什么不使用最新的api作为目标?
  • 你可以使用大于 11-19 的 api
  • 可以,但是建议你使用最新的api。
猜你喜欢
  • 1970-01-01
  • 2020-12-25
  • 1970-01-01
  • 2012-07-18
  • 2013-10-14
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
  • 1970-01-01
相关资源
最近更新 更多