By doing:

public void tutdb(View v) { try { Intent intent = new Intent(this, dbtut.class); startActivity(intent); } catch (OutOfMemoryError e) { Toast tost = Toast.makeText(getApplicationContext(),"!!!",Toast.LENGTH_SHORT); tost.show(); System.gc(); } } 

"!!!" does not come out, the application crashes: alt text

What to do (need to somehow be able to open dbtut.class)?

ps the transition takes place on the multicartic page, so if you pre-fill the operative, then it is not enough

  • You have run out of memory, and you allocate more: Toast tost = Toast.makeText (getApplicationContext (), "!!!", Toast.LENGTH_SHORT); tost.show (); Maybe first give a run to the garbage collector? And first make sure that you do not store references to objects that have clogged memory. - VladD
  • @VladD tried to change places (scavenger with toast) - it did not help (without displaying !!!)> And first make sure that you do not store references to objects that have forgotten memory. Honestly no idea. My user clicks on the button, the transition to activations with pictures takes place, then he returns by pressing the back button, selects another button, etc. Pictures after entry / exit remain in the memory, and I do not want to delete them from there until the memory runs out. Therefore, I threw System.gc into try-catch. - kandi
  • Well, does the execution even come to your catch block? Run under the debugger. --- Well, look. If you have, say, a global array containing data for all free memory minus 2 bytes, then you cannot do anything at all without deleting the excess from memory. Because any operation requires memory consumption, but you don’t have this memory. You need to free unnecessary objects. What buttons the user pushes while doing so is a minor issue. - VladD
  • not caught - because it's not there you catch - Gorets
  • one
    no, where you catch there cannot be OOM, it arises, somewhere in your work with pictures (no code, the stack is very small), then you must not catch, but work correctly with bitmap, recycle it, optimize the picture itself - Gorets

1 answer 1

An exception occurs on the 58th line in dlp.app.content.paperplanes.free.lgtut.onCreate , and try / catch should be set there. You are not there to catch.

And do not forget to recycle for unnecessary more bitmaps, in your case it will be wise to do this in the onDestroy Triggered Activity .

In general, catching OutOfMemoryError is a bad idea, because after it the stable operation of the application is not guaranteed at all, and when it does fall, an attempt to understand the cause of the problem by the standard trend will turn into an exciting quest. It is necessary to correct, and not to catch.