如何增加应用程序的内存

时间:2013-09-05 10:56:23

标签: android memory memory-management android-largeheap

如何为应用程序增加内存?

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;
    }

    }

}

2 个答案:

答案 0 :(得分:0)

您是否已将<application android:largeHeap="true" ...>定义为清单中应用程序的属性? 至少,您应该使用Honeycomb作为属性。

看一下帖子:https://stackoverflow.com/a/11275719/411951

答案 1 :(得分:0)

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

<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

我希望这可以帮到你