-1

How to increase memory for application?

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

I have this error and I'm trying apply

largeHeap="true"

but I'm getting an error:

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

My code:

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

    }

}

mmBs
  • 8,421
  • 6
  • 38
  • 46

2 Answers2

0

Have you defined <application android:largeHeap="true" ...> as attribute of the application inside your manifest? At least, you should use Honeycomb for ths attribute.

Take a look at ths post: https://stackoverflow.com/a/11275719/411951

Community
  • 1
  • 1
0xPixelfrost
  • 10,244
  • 5
  • 39
  • 58
  • i try define it like application and activity result the same – Denys Karpov Sep 05 '13 at 11:28
  • Which API level do you use? – 0xPixelfrost Sep 05 '13 at 11:41
  • i use min 7 and target version 8 – Denys Karpov Sep 05 '13 at 11:58
  • Far as i know you should use at least honeycomb (API Lvl 11) for the attribute largeHeap – 0xPixelfrost Sep 05 '13 at 12:04
  • Not really. The memory should be sufficient for normal tasks. For files like image there is a good tutorial about image caching inside the google docs. Why do you want to use the largeHeap attribute? The usual way is to improve the memory usage of your app so you should not need to enable this attribute – 0xPixelfrost Sep 05 '13 at 13:50
  • We need to know what you are doing inside your app that you have to enable the largeHeap. Without this information i can only refer to googles performance tips: http://developer.android.com/training/articles/perf-tips.html – 0xPixelfrost Sep 05 '13 at 14:55
  • so i public code of one of my activity , what help me decrease my heap? – Denys Karpov Sep 05 '13 at 15:13
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36878/discussion-between-martinvonmartinsgrun-and-denys-karpov) – 0xPixelfrost Sep 05 '13 at 15:15
0

In your manifest write this code in a application tag

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

the largeHeap attribute only appeared after API 11 or higher

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

use this codind in your manifest to set your target to API 19

I hope this help you

Jagan
  • 692
  • 1
  • 12
  • 38