Right now Im calling a new activity with an xml-view when I pause my game, but Since I do this I need to use context
in my real-time code, and this is causing a memory leak. Is there any preffered way to pause the game? By pause I mean if game is over, if I die, or if I press pause-button. Would a custom dialog work just aswell? this would mean I wont have to leave my main-activity while im in-game.
Asked
Active
Viewed 2,179 times
1

Tetrad
- 30,124
- 12
- 94
- 143

Green_qaue
- 1,893
- 4
- 24
- 55
1 Answers
1
You can use startActivityForResult, that works fine and it does not need passing the context. But in my games I've created a game object which looks like and behaves like a dialog and simply activate it on pause or game over, thus never create other activity or Android dialog.
EDIT An example using Options, which some say is safer in order to avoid out of memory errors:
private Bitmap loadBitmap(int resourceID){
Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap tempBmp = null;
try{
tempBmp = BitmapFactory.decodeStream(new BufferedInputStream(getResources().openRawResource(resourceID)), null, options);
}catch(OutOfMemoryError e){
}catch (Error e){
}
return tempBmp;
}

Lumis
- 964
- 1
- 9
- 21
getHolder().setFormat(0x00000004); //RGB_565
load bitmpas withoptions.inPreferredConfig = Bitmap.Config.RGB_565;
this is pretty interesting. Heard some stuff about this but didt know how to implement it. where do I put these 2 lines? can you update answer and tell? – Green_qaue Oct 01 '12 at 22:40bitmap = BitmapFactory.decodeResources(R.drawable.image);
so where do I put theoptions.inPreferredConfig = Bitmap.Config.RGB_565;
if I load them like this? – Green_qaue Oct 01 '12 at 22:41bitmap = loadBitmap(R.drawable.ball);
? and one last qustion, why do u useinScaled = false
? Hopefully this can reduce my heap-size a bit aswell :) – Green_qaue Oct 01 '12 at 23:37decodeStream
, when I load my images with it some get smaller then they were before(on screen), but if I usedecodeRecourse
instead it works fine. do u know why this is? – Green_qaue Oct 29 '12 at 14:57