My first post… you know…
I Created a class :
public class MyPanel extends SurfaceView implements SurfaceHolder,
SurfaceHolder.Callback {
private MediaPlayer shooting = new MediaPlayer();
public Panel(Context context, int screenWidth, int screenHeight) {
super(context);
shooting = MediaPlayer
.create(ctx, Utils.getRawResIdFromName("gunshot"));
}
void anotherMethod(){
//...
shooting.start();
}
//....other stuff....
}
Now the activity Class’s onCreate method is simple:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
... some stuff
final MyPanel panel = new MyPanel(this, newWidth, newHeight);
}
... other methods
}
My question here is how to release the resources after the user exits the activity ?
I am not sure how to release the instantiated object panel and all the objects created in it like MediaPlayer, Graphics….
Thanks
askanaan
in
onDestroy()nullify all your object variables, this will make them eligible forSystem GCto collect them. OR explicitly callSystem.gc()